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,6 +1,7 @@ | |||||||
| use std::fmt::Debug; | use std::fmt::Debug; | ||||||
| use std::hash::Hash; | use std::hash::Hash; | ||||||
| use std::mem; | use std::mem; | ||||||
|  | use std::ops::Deref; | ||||||
| 
 | 
 | ||||||
| use crate as bevy_ecs; | use crate as bevy_ecs; | ||||||
| use crate::change_detection::DetectChangesMut; | 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>`].
 | /// The next state of [`State<S>`].
 | ||||||
| ///
 | ///
 | ||||||
| /// To queue a transition, just set the contained value to `Some(next_state)`.
 | /// To queue a transition, just set the contained value to `Some(next_state)`.
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 bird
						bird