pub struct StateMachine<M>where
M: IntoStateMachine,{ /* private fields */ }Expand description
A state machine that will be lazily initialized.
Implementations§
Source§impl<M> StateMachine<M>
impl<M> StateMachine<M>
Sourcepub fn init(&mut self)where
for<'ctx> M: IntoStateMachine<Context<'ctx> = ()>,
pub fn init(&mut self)where
for<'ctx> M: IntoStateMachine<Context<'ctx> = ()>,
Explicitly initialize the state machine. If the state machine is already initialized this is a no-op.
Sourcepub fn init_with_context(&mut self, context: &mut M::Context<'_>)
pub fn init_with_context(&mut self, context: &mut M::Context<'_>)
Explicitly initialize the state machine. If the state machine is already initialized this is a no-op.
Sourcepub fn handle(&mut self, event: &M::Event<'_>)where
for<'ctx> M: IntoStateMachine<Context<'ctx> = ()>,
pub fn handle(&mut self, event: &M::Event<'_>)where
for<'ctx> M: IntoStateMachine<Context<'ctx> = ()>,
Handle an event. If the state machine is still uninitialized, it will be initialized before handling the event.
Sourcepub fn handle_with_context(
&mut self,
event: &M::Event<'_>,
context: &mut M::Context<'_>,
)
pub fn handle_with_context( &mut self, event: &M::Event<'_>, context: &mut M::Context<'_>, )
Handle an event. If the state machine is still uninitialized, it will be initialized before handling the event.
pub fn step(&mut self)
pub fn step_with_context(&mut self, context: &mut M::Context<'_>)where
for<'evt> M: IntoStateMachine<Event<'evt> = ()>,
Sourcepub fn inner(&self) -> &M
pub fn inner(&self) -> &M
Get a reference to the StateMachine’s underlying type.
let state_machine = Blinky::default().state_machine();
assert_eq!(state_machine.inner().led, false);Sourcepub unsafe fn inner_mut(&mut self) -> &mut M
pub unsafe fn inner_mut(&mut self) -> &mut M
Get a mutable reference to the StateMachine’s underlying type.
§Safety
- The user is responsible for validating that mutating a StateMachine does not break any invariants.
let mut state_machine = Blinky::default().state_machine();
unsafe {
state_machine.inner_mut().led = true;
}Sourcepub unsafe fn state_mut(&mut self) -> &mut M::State
pub unsafe fn state_mut(&mut self) -> &mut M::State
Get a mutable reference to the StateMachine’s current state.
§Safety
- The user is responsible for validating that mutating a StateMachine does not break any invariants.
let mut state_machine = Blinky::default().state_machine();
unsafe {
*state_machine.state_mut() = State::on();
}Trait Implementations§
Source§impl<M> Clone for StateMachine<M>
impl<M> Clone for StateMachine<M>
Source§impl<M> Component for StateMachine<M>
Available on crate feature bevy only.
impl<M> Component for StateMachine<M>
bevy only.Source§type Storage = TableStorage
type Storage = TableStorage
TableStorage or SparseStorage.Source§impl<M> Default for StateMachine<M>where
M: IntoStateMachine + Default,
impl<M> Default for StateMachine<M>where
M: IntoStateMachine + Default,
Source§impl<M> Deref for StateMachine<M>where
M: IntoStateMachine,
impl<M> Deref for StateMachine<M>where
M: IntoStateMachine,
Source§impl<'de, M> Deserialize<'de> for StateMachine<M>
Available on crate feature serde only.A serialized state machine can only be deserialized into an UninitializedStateMachine and can
then be initialized with init.
impl<'de, M> Deserialize<'de> for StateMachine<M>
serde only.A serialized state machine can only be deserialized into an UninitializedStateMachine and can
then be initialized with init.
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<M> From<InitializedStateMachine<M>> for StateMachine<M>where
M: IntoStateMachine,
impl<M> From<InitializedStateMachine<M>> for StateMachine<M>where
M: IntoStateMachine,
Source§fn from(value: InitializedStateMachine<M>) -> Self
fn from(value: InitializedStateMachine<M>) -> Self
Source§impl<M> From<UninitializedStateMachine<M>> for StateMachine<M>where
M: IntoStateMachine,
impl<M> From<UninitializedStateMachine<M>> for StateMachine<M>where
M: IntoStateMachine,
Source§fn from(value: UninitializedStateMachine<M>) -> Self
fn from(value: UninitializedStateMachine<M>) -> Self
Source§impl<M> PartialEq for StateMachine<M>
impl<M> PartialEq for StateMachine<M>
Source§impl<M> Serialize for StateMachine<M>
Available on crate feature serde only.
impl<M> Serialize for StateMachine<M>
serde only.impl<M> Eq for StateMachine<M>
Auto Trait Implementations§
impl<M> Freeze for StateMachine<M>
impl<M> RefUnwindSafe for StateMachine<M>
impl<M> Send for StateMachine<M>
impl<M> Sync for StateMachine<M>
impl<M> Unpin for StateMachine<M>
impl<M> UnwindSafe for StateMachine<M>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut Components, storages: &mut Storages, ids: &mut impl FnMut(ComponentId), )
unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
fn get_components(self, func: &mut impl FnMut(StorageType, OwningPtr<'_>))
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self using data from the given World.