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§
Sourcefn substate(&self) -> SubstateResult<&T>
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.
Sourcefn substate_mut(&mut self) -> SubstateResult<&mut T>
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.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".