pub struct DataSet { /* private fields */ }Expand description
Collection of arbitrary data
This struct is used to store arbitrary data in the environment.
Data stored in this struct are identified by their TypeId, so you cannot
store multiple data instances of the same type.
Implementations§
Source§impl DataSet
impl DataSet
Sourcepub fn insert<T: Clone + 'static>(&mut self, data: Box<T>) -> Option<Box<T>>
pub fn insert<T: Clone + 'static>(&mut self, data: Box<T>) -> Option<Box<T>>
Inserts a new data into the DataSet.
If data of the same type is already stored in self, it is replaced.
Returns the old data if it exists.
Sourcepub fn get<T: 'static>(&self) -> Option<&T>
pub fn get<T: 'static>(&self) -> Option<&T>
Obtains a reference to the data of the specified type.
Sourcepub fn get_mut<T: 'static>(&mut self) -> Option<&mut T>
pub fn get_mut<T: 'static>(&mut self) -> Option<&mut T>
Obtains a mutable reference to the data of the specified type.
Sourcepub fn get_or_insert_with<T, F>(&mut self, f: F) -> &mut T
pub fn get_or_insert_with<T, F>(&mut self, f: F) -> &mut T
Obtains a reference to the data of the specified type, or inserts a new data if it does not exist.
If the data does not exist, the data is created by calling the provided
closure and inserted into the DataSet, and a reference to the data is
returned. If the data already exists, a reference to the existing data
is returned and the closure is not called.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DataSet
impl !RefUnwindSafe for DataSet
impl !Send for DataSet
impl !Sync for DataSet
impl Unpin for DataSet
impl !UnwindSafe for DataSet
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more