Struct nuts::DomainState [−][src]
Stores passive data that can be accessed in event handlers of multiple activities.
A Domain stores arbitrary data for sharing between multiple Activities. Library users can define the number of domains but each activity can only join one domain.
Domains should only be used when data needs to be shared between multiple activities of the same or different types. If data is only used by a single activity, it is usually better to store it in the activity struct itself.
In case only one domain is used, you can also consider to use DefaultDomain
instead of creating your own enum.
For now, there is no real benefit from using multiple Domains, other than data isolation. But there are plans for the future that will schedule Activities in different threads, based on their domain.
Implementations
impl DomainState
[src]
pub fn store<T: Any>(&mut self, obj: T)
[src]
Stores a value in the domain. Only one instance per type id can be stored inside a domain. If an old value of the same type already exists in the domain, it will be overwritten.
pub fn try_get<T: Any>(&self) -> Option<&T>
[src]
Returns a reference to a value of the specified type, if such a value has previously been stored to the domain.
pub fn try_get_mut<T: Any>(&mut self) -> Option<&mut T>
[src]
Same as try_get
but grants mutable access to the object.
pub fn try_get_2_mut<T1: Any, T2: Any>(
&mut self
) -> (Option<&mut T1>, Option<&mut T2>)
[src]
&mut self
) -> (Option<&mut T1>, Option<&mut T2>)
Return two mutable references to domain objects
pub fn get<T: Any>(&self) -> &T
[src]
Returns a reference to a value of the specified type, taken from the domain.
Panics
Panics if object of that type has not been stored previously.
try_get()
is usually recommended instead.
pub fn get_mut<T: Any>(&mut self) -> &mut T
[src]
Returns a mutable reference to a value of the specified type, taken from the domain.
Panics
Panics if object of that type has not been stored previously
try_get_mut()
is usually recommended instead.
Trait Implementations
impl Default for DomainState
[src]
fn default() -> DomainState
[src]
Auto Trait Implementations
impl !RefUnwindSafe for DomainState
impl !Send for DomainState
impl !Sync for DomainState
impl Unpin for DomainState
impl !UnwindSafe for DomainState
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,