pub struct World { /* private fields */ }Expand description
A type-safe container for storing and retrieving resources by their type.
World acts as a central storage for application state, allowing you to insert,
retrieve, and remove resources of any type. Each type can only have one instance
stored at a time.
By default, World is initialized with Focus, Keybindings, and Pointer
resources.
§Example
ⓘ
let mut world = World::default();
// Insert a custom resource
world.insert(MyAppState::new());
// Retrieve it later
let state = world.get::<MyAppState>();Implementations§
Source§impl World
impl World
pub fn new() -> Self
pub fn insert<R: Any>(&mut self, res: R)
Sourcepub fn get_mut<R: Any>(&mut self) -> &mut R
pub fn get_mut<R: Any>(&mut self) -> &mut R
§Panics
Panics if the resource of type R is not found.
pub fn try_get<R: Any>(&self) -> Option<&R>
pub fn try_get_mut<R: Any>(&mut self) -> Option<&mut R>
pub fn exists<R: Any>(&self) -> bool
pub fn remove<R: Any>(&mut self) -> Option<R>
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for World
impl !Send for World
impl !Sync for World
impl !UnwindSafe for World
impl Forget for World
impl Freeze for World
impl Unpin for World
impl UnsafeUnpin for World
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more