BehaviorItem

Trait BehaviorItem 

Source
pub trait BehaviorItem {
    // Required methods
    fn current(&self) -> &Self::Behavior;
    fn previous(&self) -> Option<&Self::Behavior>;
    fn current_index(&self) -> BehaviorIndex;
    fn enumerate(
        &self,
    ) -> impl Iterator<Item = (BehaviorIndex, &Self::Behavior)> + '_;
    fn get(&self, index: BehaviorIndex) -> Option<&Self::Behavior>;
    fn has_transition(&self) -> bool;

    // Provided methods
    fn index(&self) -> BehaviorIndex { ... }
    fn has_index(&self, index: BehaviorIndex) -> bool { ... }
    fn iter(&self) -> impl Iterator<Item = &Self::Behavior> + '_ { ... }
}
Expand description

Common interface for querying Behavior state using a BehaviorRef or BehaviorMut.

Required Methods§

Source

fn current(&self) -> &Self::Behavior

Returns the current Behavior state.

Source

fn previous(&self) -> Option<&Self::Behavior>

Returns the previous Behavior state in the stack.

§Usage

Note that this is NOT the previously active state. Instead, this is the previous state which was active before the current one was started.

To access the previously active state, handle Stop instead.

Source

fn current_index(&self) -> BehaviorIndex

Returns the BehaviorIndex associated with the current Behavior state.

Source

fn enumerate( &self, ) -> impl Iterator<Item = (BehaviorIndex, &Self::Behavior)> + '_

Returns an iterator over all (BehaviorIndex, Behavior) pairs in the stack, including the current one.

The iterator is ordered from the initial behavior (index = 0) to the current one.

Source

fn get(&self, index: BehaviorIndex) -> Option<&Self::Behavior>

Returns a reference to the Behavior at the given BehaviorIndex, if it exists.

Source

fn has_transition(&self) -> bool

Returns true if there is any pending Transition for this Behavior.

§Usage

By design, only one transition is allowed per transition cycle.

The only exception to this rule is if the behavior is interrupted or reset where multiple states may be stopped within a single cycle.

If a transition is requested while another is pending, it would be overriden. The transition helper methods start, interrupt_start, stop and reset all trigger a warning in this case.

Because of this, this method is useful to avoid unintentional transition overrides.

Provided Methods§

Source

fn index(&self) -> BehaviorIndex

👎Deprecated since 0.3.1: use current_index instead

Returns the BehaviorIndex associated with the current Behavior state.

Source

fn has_index(&self, index: BehaviorIndex) -> bool

Returns true if the given BehaviorIndex matches a state in this Behavior stack.

Source

fn iter(&self) -> impl Iterator<Item = &Self::Behavior> + '_

Returns an iterator over all Behavior states in the stack, including the current one.

The iterator is ordered from the initial behavior (index = 0) to the current one.

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§