Initial commit
This commit is contained in:
commit
8034b71058
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static_alt"
|
||||
version = "0.1.0"
|
6
Cargo.toml
Normal file
6
Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "lazy_static_alt"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
10
src/bin/lazylock.rs
Normal file
10
src/bin/lazylock.rs
Normal 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
15
src/bin/oncelock.rs
Normal 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!
|
||||
}
|
Loading…
Reference in New Issue
Block a user