Trait SubstateAccess

Source
pub trait SubstateAccess<T> {
    // Required methods
    fn substate(&self) -> SubstateResult<&T>;
    fn substate_mut(&mut self) -> SubstateResult<&mut T>;
}
Expand description

A trait for obtaining immutable and mutable references to a substate of type T.

§Example

impl SubstateAccess<P2pState> for State {
   fn substate(&self) -> SubstateResult<&P2pState> {
       self.p2p
           .ready()
           .ok_or_else(|| "P2P state unavailable. P2P layer is not ready".to_owned())
   }

   fn substate_mut(&mut self) -> SubstateResult<&mut P2pState> {
       self.p2p
           .ready_mut()
           .ok_or_else(|| "P2P state unavailable. P2P layer is not ready".to_owned())
   }
 }

Required Methods§

Source

fn substate(&self) -> SubstateResult<&T>

Attempts to obtain an immutable reference to the substate.

In case of failure, an error String describing the reason is returned.

Source

fn substate_mut(&mut self) -> SubstateResult<&mut T>

Attempts to obtain a mutable reference to the substate.

In case of failure, an error String describing the reason is returned.

Implementors§