RusPiRo Singleton crate
This crate provides an easy to use singleton pattern that is safe to be used across cores.
Usage
To use this crate simply add the dependency to your Cargo.toml
file:
[]
= "0.3"
Once done on any rust file you can define a static variable as singleton of any type for safe cross core access like so:
// define the static variable
static DEMO: = new;
// define the type to be accessible as singleton
// implement the type that should provided as singlton
If the singleton does only require read only
access a non-blocking function could be used:
Limitation
The current version of the implementation does not allow lazy initialization. Only const fn
functions can be used to initialize the structure instance that should be wrapped by the Singleton
.
License
Licensed under Apache License, Version 2.0, (LICENSE or http://www.apache.org/licenses/LICENSE-2.0)