Skip to main content

Policy

Trait Policy 

Source
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§

Source

const UNINIT_STATE: Self::State

An instance of state in the uninitialized condition.

Required Associated Types§

Source

type State

Associated storage for state tracking.

Required Methods§

Source

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§

Source

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".

Implementors§