mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
implement Deref
for State<S>
(#8668)
# Objective - Allow for directly call methods on states without first calling `state.get().my_method()` ## Solution - Implement `Deref` for `State<S>` with `Target = S` --- *I did not implement `DerefMut` because states hold no data and should only be changed via `NextState::set()`*
This commit is contained in:
parent
a9ca40506e
commit
bc9144bcd6
1 changed files with 9 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
use std::mem;
|
||||
use std::ops::Deref;
|
||||
|
||||
use crate as bevy_ecs;
|
||||
use crate::change_detection::DetectChangesMut;
|
||||
|
@ -95,6 +96,14 @@ impl<S: States> PartialEq<S> for State<S> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S: States> Deref for State<S> {
|
||||
type Target = S;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.get()
|
||||
}
|
||||
}
|
||||
|
||||
/// The next state of [`State<S>`].
|
||||
///
|
||||
/// To queue a transition, just set the contained value to `Some(next_state)`.
|
||||
|
|
Loading…
Reference in a new issue