Attribute Macro singleton

Source
#[singleton]
Expand description

A macro to define a singleton struct.

There are two modes:

  • Default(#[singleton]): Returns a static reference to Self.
  • #[singleton(arc)]: Returns an &'static Arc<Self>, allowing for shared ownership across threads.

Usage:

use qsingleton::singleton;

#[singleton]
#[derive(Debug)]
struct Config {
   name: String,
   version: String,
}  

#[singleton(arc)]
#[derive(Debug)]
struct Database {
   connection_string: String,
   pool_size: usize,
}