2 个版本
| 0.1.2 | 2024 年 5 月 30 日 | 
|---|---|
| 0.1.1 | 2024 年 5 月 30 日 | 
| 0.1.0 |  | 
#2114 在 Rust 模式
5KB
71 行
lazier_static
描述
在 std::sync::OnceLock 上的一层薄包装,提供缓存的、懒的、静态初始化。
示例
use lazier_static::*;
lazier_static! {
    fn hello_world() -> &str {
        "Hello, World!"
    }
    fn number() -> i32 {
        10 * 32
    }
}
fn main() {
    println!("{}", number());
}
用法
cargo 命令
cargoadd lazier_static
Cargo.toml
lazier_static= "0.1.2"
许可证
MIT OR Apache-2.0
lib.rs:
lazier_static
在 std::sync::OnceLock 上包装的一层,提供缓存的、静态的、懒初始化。
use lazier_static::*;
lazier_static! {
    fn hello_world() -> &str {
        "Hello, World!"
    }
}
//...
fn main() {
    println!("{}", hello_world());
}
许可证
MIT OR Apache-2.0