Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scopeguard #127

Open
FeldrinH opened this issue Jun 27, 2024 · 2 comments
Open

Add scopeguard #127

FeldrinH opened this issue Jun 27, 2024 · 2 comments

Comments

@FeldrinH
Copy link

A utility/language extension that I quite like and which seems to be fairly commonly used (looking at the numbers on crates.io) is scopeguard, which adds a helper function and convenience macro for deferred cleanup actions (similar to the defer statement in Go).

@djc
Copy link
Contributor

djc commented Jun 28, 2024

28M recent downloads, so it qualifies as popular at least...

I ran into this recently but I'm honestly not much of a fan, feels more idiomatic (and not much more verbose) to just define a guard type with a Drop impl.

@FeldrinH
Copy link
Author

I guess it's a matter of taste. I personally like it because it allows me to have cleanup logic in the method body, close to the rest of the method code, rather than in a separate Drop impl. I find it more readable than the alternatives for cleanup logic that is specific to one method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants