Trait OptionDiffDomain

Source
pub trait OptionDiffDomain {
    type Domain: Domain<State = Self::State, Diff = Option<Self::State>>;
    type State: Clone;

    // Provided methods
    fn get_cur_state(
        state_diff: StateDiffRef<'_, Self::Domain>,
    ) -> &<<Self as OptionDiffDomain>::Domain as Domain>::State { ... }
    fn get_cur_state_mut(
        state_diff: StateDiffRefMut<'_, Self::Domain>,
    ) -> &mut <<Self as OptionDiffDomain>::Domain as Domain>::State { ... }
}
Expand description

In case your domain has a Diff that is an Option of its State, provides helper functions to retrieve the state in your tasks.

The functions get_cur_state and get_cur_state_mut are available when read-only, respectively read-write, access is required. In that case, just use the trait in your task files: use npc_engine_utils::OptionDiffDomain;.

Required Associated Types§

Source

type Domain: Domain<State = Self::State, Diff = Option<Self::State>>

Source

type State: Clone

Provided Methods§

Source

fn get_cur_state( state_diff: StateDiffRef<'_, Self::Domain>, ) -> &<<Self as OptionDiffDomain>::Domain as Domain>::State

Returns either the diff if it is not None, or the initial_state.

Source

fn get_cur_state_mut( state_diff: StateDiffRefMut<'_, Self::Domain>, ) -> &mut <<Self as OptionDiffDomain>::Domain as Domain>::State

Returns either the diff if it is not None, or copies the initial_state into the diff and returns it.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<S: Debug + Sized + Clone + Hash + Eq, DA: Debug + Default, D: Domain<State = S, Diff = Option<S>, DisplayAction = DA>> OptionDiffDomain for D

Source§

type Domain = D

Source§

type State = <D as Domain>::State