3 unstable releases
0.2.0 | Jul 3, 2024 |
---|---|
0.1.1 | Jul 3, 2024 |
0.1.0 | Nov 9, 2023 |
#851 in Algorithms
29 downloads per month
7KB
72 lines
NOTE: Do not use this! LazyCell has been standardized and is better!
EasyLazy - Lazy initialization made easy
Looking at the available options for lazy initialization, I found that the most required jumping through odd, unnecessary hoops. EasyLazy aims to make lazy initialization of a variable lightweight and easy.
EasyLazy has only 3 requirements:
- T must implement Clone
- T must implement Default with a cheap operation
- The Lazy variable must be mutable so that it can be initialized
Usage
use easylazy::Lazy;
let mut my_lazy_variable = Lazy::new(Box::new(|| 10));
// my_lazy_variable is uninitialized here
assert_eq!(my_lazy_variable.get(), 10);
my_lazy_variable.get_mut() = 20;
assert_eq!(my_lazy_variable.get(), 20);
lib.rs
:
EasyLazy - Lazy initialization made easy
Looking at the available options for lazy initialization, I found that the most required jumping through odd, unnecessary hoops. EasyLazy aims to make lazy initialization of a variable lightweight and easy.
EasyLazy has only 3 requirements:
- T must implement Clone
- T must implement Default with a cheap operation
- The Lazy variable must be mutable so that it can be initialized
Lazy is Send & Sync so long as T is Send & Sync. Please make sure that your calculation is also thread safe before assuming YOUR Lazy variable is Send & Sync.