| Crates.io | proc-singleton |
| lib.rs | proc-singleton |
| version | 0.2.0 |
| created_at | 2025-04-10 06:58:47.181795+00 |
| updated_at | 2025-06-01 02:08:32.72245+00 |
| description | Rust proc-macros for implement Singleton Pattern |
| homepage | https://github.com/jonhteper/proc-singleton |
| repository | https://github.com/jonhteper/proc-singleton |
| max_upload_size | |
| id | 1627724 |
| size | 12,590 |
Rust proc-macros for impl singleton
use std::sync::LazyLock;
use uuid::Uuid;
use proc_singleton::Singleton;
static IDENT: LazyLock<Identifier> = LazyLock::new(|| {
Identifier {
id: Uuid::new_v4(),
}
});
#[derive(Singleton)]
#[singleton(IDENT)]
struct Identifier {
id: Uuid,
}
fn main() {
let instance = Identifier::get_instance();
let ptr = instance as *const Identifier;
let same_ptr = Identifier::get_instance() as *const Identifier;
assert_eq!(ptr, same_ptr);
}
use std::sync::LazyLock;
use uuid::Uuid;
use proc_singleton::singleton_from_static;
#[singleton_from_static(Identifier)]
static IDENT: LazyLock<Identifier> = LazyLock::new(|| {
Identifier {
id: Uuid::new_v4(),
}
});
struct Identifier {
id: Uuid,
}
fn main() {
let instance = Identifier::get_instance();
let ptr = instance as *const Identifier;
let same_ptr = Identifier::get_instance() as *const Identifier;
assert_eq!(ptr, same_ptr);
}