pub struct LazyExclusive<T> { /* private fields */ }
Expand description
A container type like LazyLock
.
Allows mutable access, but only one reference at a time.
use lazy_exclusive::LazyExclusive;
static LAZY: LazyExclusive<i32> = LazyExclusive::new(123);
let lock = LAZY.get().unwrap();
assert_eq!(*lock, 123);
assert!(LAZY.is_locked());
Implementations§
Source§impl<T> LazyExclusive<T>
impl<T> LazyExclusive<T>
pub const fn new(data: T) -> Self
Sourcepub fn get(&self) -> Option<Mut<'_, T>>
pub fn get(&self) -> Option<Mut<'_, T>>
Get a handle to the inner data. Returns None
if a handle already exists
Sourcepub fn swap(&self, new_value: T)
pub fn swap(&self, new_value: T)
Set the inner value to [new_value
]. Panics if the data is already locked
pub const fn get_state(&self) -> State
pub fn into_inner(self) -> T
pub const fn is_unlocked(&self) -> bool
pub const fn is_locked(&self) -> bool
pub const fn is_poisoned(&self) -> bool
Trait Implementations§
Source§impl<T: Clone> Clone for LazyExclusive<T>
impl<T: Clone> Clone for LazyExclusive<T>
Source§impl<T: Debug> Debug for LazyExclusive<T>
impl<T: Debug> Debug for LazyExclusive<T>
Source§impl<T: Default> Default for LazyExclusive<T>
impl<T: Default> Default for LazyExclusive<T>
Source§impl<T> From<T> for LazyExclusive<T>
impl<T> From<T> for LazyExclusive<T>
impl<T> Send for LazyExclusive<T>
impl<T> Sync for LazyExclusive<T>
Auto Trait Implementations§
impl<T> !Freeze for LazyExclusive<T>
impl<T> !RefUnwindSafe for LazyExclusive<T>
impl<T> Unpin for LazyExclusive<T>where
T: Unpin,
impl<T> UnwindSafe for LazyExclusive<T>where
T: UnwindSafe,
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