pub struct DomainState { /* private fields */ }
Expand description
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§
Source§impl DomainState
impl DomainState
Sourcepub fn store<T: Any>(&mut self, obj: T)
pub fn store<T: Any>(&mut self, obj: T)
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.
Sourcepub fn try_get<T: Any>(&self) -> Option<&T>
pub fn try_get<T: Any>(&self) -> Option<&T>
Returns a reference to a value of the specified type, if such a value has previously been stored to the domain.
Sourcepub fn try_get_mut<T: Any>(&mut self) -> Option<&mut T>
pub fn try_get_mut<T: Any>(&mut self) -> Option<&mut T>
Same as try_get
but grants mutable access to the object.
Sourcepub fn try_get_2_mut<T1: Any, T2: Any>(
&mut self,
) -> (Option<&mut T1>, Option<&mut T2>)
pub fn try_get_2_mut<T1: Any, T2: Any>( &mut self, ) -> (Option<&mut T1>, Option<&mut T2>)
Return two mutable references to domain objects