-
Notifications
You must be signed in to change notification settings - Fork 33
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
Implement lazy_static
support
#93
Conversation
This change adds support for the `lazy_static` crate. It's mostly built around a `Once` cell for each static plus some global storage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. One issue is that lazy_static
does not run Drop methods on the type. However, this version will run the destructors.
We can either (1) alert users to this difference, or (2) do std::mem::forget
on the value when we finish an execution?
@@ -414,3 +415,64 @@ macro_rules! __thread_local_inner { | |||
}; | |||
} | |||
} | |||
|
|||
/// Declare a new [lazy static value](crate::lazy_static::Lazy), like the `lazy_static` crate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about also adding lazy_static::initialize
? (Not that I've seen anyone ever using it...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually used this the other day, so added :-)
tests/basic/lazy_static.rs
Outdated
} | ||
|
||
#[test] | ||
fn mutex_dfs() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you improve the test name, and add a comment -- this test checks that DFS will explore the N! interleavings during initialization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, and ended up refactoring a little to share the two tests.
This change adds support for the
lazy_static
crate. It's mostly built around aOnce
cell for each static plus some global storage.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.