singleton_attr/
traits.rs

1use std::sync::{LockResult, MutexGuard};
2
3/// Unsafe singleton
4///
5/// `Singleton::init_instance` - (re)initialize the singleton, prefer to use this if you want more control with the initial instance.
6/// `Singleton::get_instance` - get the singleton instance, if the instance is not initialized, it will initialize it with the default value.
7pub trait Singleton: Default {
8    fn init_instance(instance: Self);
9    fn get_instance() -> &'static mut Self;
10}
11
12/// Safe singleton
13///
14/// `Singleton::init_instance` - (re)initialize the singleton, prefer to use this if you want more control with the initial instance.
15/// `Singleton::get_instance` - get the singleton instance, if the instance is not initialized, it will initialize it with the default value.
16pub trait SafeSingleton: Default {
17    fn init_instance(instance: Self);
18    fn get_instance() -> LockResult<MutexGuard<'static, Self>>;
19}