[][src]Struct nuts::DomainState

pub struct DomainState { /* fields omitted */ }

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]

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]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.