pub struct Global<T> { /* private fields */ }
Expand description
Lazily evaluated static allocation.
Implementations§
Source§impl<T> Global<T>
impl<T> Global<T>
Sourcepub const fn new(f: fn() -> T) -> Self
pub const fn new(f: fn() -> T) -> Self
Constructs a new global. Rather than a value, this function takes a closure that produces a value.
static MY_TABLE: Global<Vec<&str>> = Global::new(|| vec!["a", "b", "c"]);
Sourcepub fn get(&self) -> Option<&T>
pub fn get(&self) -> Option<&T>
Retrieves a reference to the value inside the global without allocating.
This function will return None
if the global has not been allocated.
Sourcepub unsafe fn get_unchecked(&self) -> &T
pub unsafe fn get_unchecked(&self) -> &T
Retrieves a reference to the value inside the global without allocating. Calling this function on an unallocated global is undefined behavior.
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for Global<T>
impl<T> RefUnwindSafe for Global<T>where
T: RefUnwindSafe,
impl<T> Send for Global<T>
impl<T> Sync for Global<T>
impl<T> Unpin for Global<T>
impl<T> UnwindSafe for Global<T>where
T: RefUnwindSafe,
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