Struct DomainState

Source
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

Source

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.

Source

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.

Source

pub fn try_get_mut<T: Any>(&mut self) -> Option<&mut T>

Same as try_get but grants mutable access to the object.

Source

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

Source

pub fn get<T: Any>(&self) -> &T

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.

Source

pub fn get_mut<T: Any>(&mut self) -> &mut T

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§

Source§

impl Default for DomainState

Source§

fn default() -> DomainState

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Activity for T
where T: Any,