pub trait Policy {
type State;
const UNINIT_STATE: Self::State;
// Required method
fn transition(state: &Self::State, from: Lifecycle, to: Lifecycle);
// Provided method
fn init_with<R, E>(
state: &Self::State,
init_fn: impl FnOnce() -> Result<R, E>,
) -> Result<R, E> { ... }
}Expand description
Lifecycle and storage policy for initialization state.
Required Associated Constants§
Sourceconst UNINIT_STATE: Self::State
const UNINIT_STATE: Self::State
An instance of state in the uninitialized condition.
Required Associated Types§
Required Methods§
Sourcefn transition(state: &Self::State, from: Lifecycle, to: Lifecycle)
fn transition(state: &Self::State, from: Lifecycle, to: Lifecycle)
Transitions state from from to to, panicking if the current state
does not match from.
Provided Methods§
Sourcefn init_with<R, E>(
state: &Self::State,
init_fn: impl FnOnce() -> Result<R, E>,
) -> Result<R, E>
fn init_with<R, E>( state: &Self::State, init_fn: impl FnOnce() -> Result<R, E>, ) -> Result<R, E>
Executes init_fn to construct the wrapped value within an
initialization transition.
Transitions to the initialized state if init_fn succeeds with Ok, or
reverts to the uninitialized state if it returns Err.
§Panics
Panics if the instance is not currently uninitialized.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".