Initial commit

This commit is contained in:
2025-02-03 11:43:07 +01:00
commit 8034b71058
5 changed files with 39 additions and 0 deletions

10
src/bin/lazylock.rs Normal file
View File

@@ -0,0 +1,10 @@
use std::sync::LazyLock;
static GLOBAL_DATA: LazyLock<String> = LazyLock::new(|| {
// Initialize the global data here
"Hello, world!".to_string()
});
fn main() {
println!("{}", *GLOBAL_DATA); // Output: Hello, world!
}

15
src/bin/oncelock.rs Normal file
View File

@@ -0,0 +1,15 @@
use std::sync::OnceLock;
static GLOBAL_DATA: OnceLock<String> = OnceLock::new();
fn get_global_data() -> &'static String {
GLOBAL_DATA.get_or_init(|| {
// Initialize the global data here
"Hello, world!".to_string()
})
}
fn main() {
let data = get_global_data();
println!("{}", data); // Output: Hello, world!
}