Spent 45 mins earlier today writing a new (ish) implementation of a scope guard impl:
https://docs.rs/mini-scopeguard
This feels like something that should exist in the stdlib, and I think I might submit this for inclusion as core::drop::Guard
(or some variation on that name).
=> More informations about this toot | More toots from yosh@toot.yosh.is
@yosh I was trying to read the source code to understand how it works, and noticed this comment:
https://docs.rs/mini-scopeguard/latest/src/mini_scopeguard/lib.rs.html#150
test copied from .../latest/...#1-595
I think you should link to an exact version, so that the line numbers don't drift over time
=> More informations about this toot | More toots from robinm@fosstodon.org
@yosh That being said, I have no clue how it works. I don't understand how the first argument of new() can be taken by value and still be used after
=> More informations about this toot | More toots from robinm@fosstodon.org
@robinm the magic is in the deref impls. This is the same trait that makes e.g. Mutex, Box, Arc, etc work
=> More informations about this toot | More toots from yosh@toot.yosh.is This content has been proxied by September (ba2dc).Proxy Information
text/gemini