Initial commit

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

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

7
Cargo.lock generated Normal file
View 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
View File

@ -0,0 +1,6 @@
[package]
name = "lazy_static_alt"
version = "0.1.0"
edition = "2024"
[dependencies]

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!
}