pub struct Singleton { /* private fields */ }
Expand description
Base instance for Singleton storage
Implementations§
source§impl Singleton
impl Singleton
sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty Singleton Storage
§Examples
use singly::Singleton;
let mut instance = Singleton::new();
instance.set(32i32);
instance.set(12f32);
assert_eq!(instance.get::<i32>(), &32);
assert_eq!(instance.get::<f32>(), &12f32);
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates an empty Singleton Storage with specified capacity
§Examples
use singly::Singleton;
let mut instance = Singleton::with_capacity(2);
instance.set(32i32);
instance.set(12f32);
assert_eq!(instance.get::<i32>(), &32);
assert_eq!(instance.get::<f32>(), &12f32);
sourcepub fn set<T: Any>(&mut self, data: T)
pub fn set<T: Any>(&mut self, data: T)
Store the data to Singleton
storage
Will silently overwrite old value if any
sourcepub fn try_get<T: Any>(&self) -> Option<&T>
pub fn try_get<T: Any>(&self) -> Option<&T>
Get reference to data from global storage. Will return None if there is no data available with this type.
sourcepub fn get<T: Any>(&self) -> &T
pub fn get<T: Any>(&self) -> &T
Get reference to data from global storage.
§Panic
May panic if there is no data available with this type
sourcepub fn try_get_mut<T: Any>(&mut self) -> Option<&mut T>
pub fn try_get_mut<T: Any>(&mut self) -> Option<&mut T>
Get mutabler eference to data from global storage. Will return None if there is no data available with this type.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Singleton
impl !RefUnwindSafe for Singleton
impl Send for Singleton
impl Sync for Singleton
impl Unpin for Singleton
impl !UnwindSafe for Singleton
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more