-
Notifications
You must be signed in to change notification settings - Fork 109
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 a warning in the FAQ about const
vs static
#145
Comments
I just made this exact mistake (playground): use once_cell::unsync::OnceCell; // 1.9.0
const CELL: OnceCell<bool> = OnceCell::new();
pub fn main() {
assert_eq!(CELL.set(true), Ok(()));
assert_eq!(CELL.set(true), Err(true)); // Fails
} I assume based on the linked rust-lang conversation that there's no way for |
I also just hit this. I wonder if perhaps there could be a debug panic if a lazy is initialized twice saying the user likley has it in a |
I think some people may have some misconceptions about what
const
andstatic
actually means, this came up in this reddit thread today. I tried explaining shortly by analogy (I'm not the best explainer), the result of the constructor function is copy pasted everywhere the const result is used. Maybe this could warrant a reminder note in the FAQ part of the docs ?The text was updated successfully, but these errors were encountered: