Struct ambient_api::prelude::State
source · pub struct State<T>(/* private fields */)
where
T: ?Sized;
Expand description
A wrapper for Arc<RwLock<T>>
to simplify passing complex state around callbacks.
Where possible, prefer using the ECS and storing data in (custom) components. This allows
other modules to introspect your module’s state, and is generally easier to work with (as
EntityId is Copy
, unlike this type.)
Implementations§
source§impl<T> State<T>
impl<T> State<T>
sourcepub fn read(&self) -> RwLockReadGuard<'_, T>
pub fn read(&self) -> RwLockReadGuard<'_, T>
Immutably borrows the state. Use this to access the state without modifying it.
sourcepub fn write(&self) -> RwLockWriteGuard<'_, T>
pub fn write(&self) -> RwLockWriteGuard<'_, T>
Mutably borrows the state. Use this to modify the state.
Trait Implementations§
Auto Trait Implementations§
impl<T: ?Sized> RefUnwindSafe for State<T>
impl<T: ?Sized> Send for State<T>
impl<T: ?Sized> Sync for State<T>
impl<T: ?Sized> Unpin for State<T>
impl<T: ?Sized> UnwindSafe for State<T>
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
Mutably borrows from an owned value. Read more
source§impl<T> Downcast for T
impl<T> Downcast for T
source§impl<T> ElementComponentName for T
impl<T> ElementComponentName for T
source§fn element_component_name(&self) -> &'static str
fn element_component_name(&self) -> &'static str
Returns the name of the type implementing ElementComponent.