pub struct Slot<T> { /* private fields */ }
Expand description
Atomically Swappable Option<Box<T>>
Implementations§
Source§impl<T> Slot<T>
impl<T> Slot<T>
pub const NONE: Self
Sourcepub fn new(item: Box<T>) -> Self
pub fn new(item: Box<T>) -> Self
Creates a new Slot
with an initial item inside.
To create an empty slot, use Slot::default()
or Slot::NONE
.
Sourcepub fn try_insert(&self, item: Box<T>) -> Result<(), Box<T>>
pub fn try_insert(&self, item: Box<T>) -> Result<(), Box<T>>
Tries to push an item into this slot, failing if it’s occupied or locked.
Sourcepub fn insert(&self, item: Box<T>) -> Option<Box<T>>
pub fn insert(&self, item: Box<T>) -> Option<Box<T>>
Forcibly pushes an item into this slot, returning the previous content
This discards the “locked” flag.
Sourcepub fn try_take(&self, lock: bool) -> Option<Box<T>>
pub fn try_take(&self, lock: bool) -> Option<Box<T>>
Tries to extract the contained item.
Setting lock
to true
will prevent pushing into this slot again.
pub fn is_locked(&self) -> bool
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for Slot<T>
impl<T> RefUnwindSafe for Slot<T>
impl<T> Send for Slot<T>
impl<T> Sync for Slot<T>
impl<T> Unpin for Slot<T>
impl<T> UnwindSafe for Slot<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