| Crates.io | slazy |
| lib.rs | slazy |
| version | 0.1.0 |
| created_at | 2023-11-28 19:24:59.244881+00 |
| updated_at | 2023-11-28 19:24:59.244881+00 |
| description | A simple, small, no-std, macro-based lazy static library for Rust. |
| homepage | |
| repository | https://github.com/Brian3647/slazy |
| max_upload_size | |
| id | 1052301 |
| size | 5,330 |
A simple, small, no-std, macro-based lazy static library for Rust.
cargo add slazy or by adding the following to your Cargo.toml:
[dependencies]
slazy = "*"
use slazy::slazy;
slazy! {
pub FOO: u32 = {
println!("Evaluating FOO");
42
};
BAR: u32 = 1337;
}
println!("FOO: {}", *FOO); // Evaluates FOO
println!("{}", *FOO); // Gets the value of FOO without evaluating it again
println!("{}", *BAR); // Evaluates BAR
[!WARNING] If you want to use SLazy in a multi-threaded environment, you should initialize the lazy statics before spawning any threads. This is because the lazy statics might not be thread safe in certain scenarios due to data races.
use slazy::{slazy, init};
slazy! {
pub FOO: u32 = {
println!("Evaluating FOO");
42
};
}
init!(FOO); // or `_ = *FOO;`
std::thread::spawn(|| {
println!("{}", *FOO); // Safe to use FOO in this thread
});
This project is licensed under the MIT license.