Enum State

Source
pub enum State<A, S> {
Show 14 variants WaitForPressedState(Button), WaitForReleasedState(Button), ActionState(A, Option<S>), FailState(Box<State<A, S>>), AlwaysSucceedState(Box<State<A, S>>), WaitState(f64, f64), WaitForeverState, IfState(Box<Behavior<A>>, Box<Behavior<A>>, Status, Box<State<A, S>>), SelectState(Vec<Behavior<A>>, usize, Box<State<A, S>>), SequenceState(Vec<Behavior<A>>, usize, Box<State<A, S>>), WhileState(Box<State<A, S>>, Vec<Behavior<A>>, usize, Box<State<A, S>>), WhenAllState(Vec<Option<State<A, S>>>), WhenAnyState(Vec<Option<State<A, S>>>), AfterState(usize, Vec<State<A, S>>),
}
Expand description

Keeps track of a behavior.

Variants§

§

WaitForPressedState(Button)

Returns Success when button is pressed.

§

WaitForReleasedState(Button)

Returns Success when button is released.

§

ActionState(A, Option<S>)

Executes an action.

§

FailState(Box<State<A, S>>)

Converts Success into Failure and vice versa.

§

AlwaysSucceedState(Box<State<A, S>>)

Ignores failures and always return Success.

§

WaitState(f64, f64)

Keeps track of waiting for a period of time before continuing.

f64: Total time in seconds to wait

f64: Time elapsed in seconds

§

WaitForeverState

Waits forever.

§

IfState(Box<Behavior<A>>, Box<Behavior<A>>, Status, Box<State<A, S>>)

Keeps track of an If behavior. If status is Running, then it evaluates the condition. If status is Success, then it evaluates the success behavior. If status is Failure, then it evaluates the failure behavior.

§

SelectState(Vec<Behavior<A>>, usize, Box<State<A, S>>)

Keeps track of a Select behavior.

§

SequenceState(Vec<Behavior<A>>, usize, Box<State<A, S>>)

Keeps track of an Sequence behavior.

§

WhileState(Box<State<A, S>>, Vec<Behavior<A>>, usize, Box<State<A, S>>)

Keeps track of a While behavior.

§

WhenAllState(Vec<Option<State<A, S>>>)

Keeps track of a WhenAll behavior.

§

WhenAnyState(Vec<Option<State<A, S>>>)

Keeps track of a WhenAny behavior.

§

AfterState(usize, Vec<State<A, S>>)

Keeps track of an After behavior.

Implementations§

Source§

impl<A: Clone, S> State<A, S>

Source

pub fn new(behavior: Behavior<A>) -> Self

Creates a state from a behavior.

Source

pub fn event<E, F>(&mut self, e: &E, f: &mut F) -> (Status, f64)
where E: GenericEvent, F: FnMut(ActionArgs<'_, E, A, S>) -> (Status, f64),

Updates the cursor that tracks an event.

The action need to return status and remaining delta time. Returns status and the remaining delta time.

Passes event, delta time in seconds, action and state to closure. The closure should return a status and remaining delta time.

Trait Implementations§

Source§

impl<A: Clone, S: Clone> Clone for State<A, S>

Source§

fn clone(&self) -> State<A, S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'de, A, S> Deserialize<'de> for State<A, S>
where A: Deserialize<'de>, S: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<A: PartialEq, S: PartialEq> PartialEq for State<A, S>

Source§

fn eq(&self, other: &State<A, S>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A, S> Serialize for State<A, S>
where A: Serialize, S: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<A, S> StructuralPartialEq for State<A, S>

Auto Trait Implementations§

§

impl<A, S> Freeze for State<A, S>
where A: Freeze, S: Freeze,

§

impl<A, S> RefUnwindSafe for State<A, S>

§

impl<A, S> Send for State<A, S>
where A: Send, S: Send,

§

impl<A, S> Sync for State<A, S>
where A: Sync, S: Sync,

§

impl<A, S> Unpin for State<A, S>
where A: Unpin, S: Unpin,

§

impl<A, S> UnwindSafe for State<A, S>
where A: UnwindSafe, S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,