macro_rules! new_singleton {
    ( $pub:vis $Name:ident ) => { ... };
}
Expand description

Generates a new global singleton type with a fallible constructor. This is intended for cases where a single instance is created early in the program and passed throughout.

This is one way to create a Singleton which is ’static and Send/Sync

#[macro_use] extern crate singleton_cell;
new_singleton!(pub Token);
fn main() {
    let tok = Token::new().expect("Main called only once");

    // possibly combine with Erased borrows
    use singleton_trait::Erased;
    let tok = Erased::new(tok);

}

This method will return Some the first time it is called, and None any time thereafter. This does not establish any ordering between multiple threads if they access at the same time.