Struct bones_lib::ecs::prelude::AtomicResource
source · pub struct AtomicResource<T>where
T: HasSchema,{ /* private fields */ }
Expand description
A handle to a resource from a Resources
collection.
This is not the resource itself, but a cheaply clonable handle to it.
To access the resource you must borrow it with either borrow()
or
borrow_mut()
.
Implementations§
source§impl<T> AtomicResource<T>where
T: HasSchema,
impl<T> AtomicResource<T>where
T: HasSchema,
sourcepub fn empty() -> AtomicResource<T>
pub fn empty() -> AtomicResource<T>
Create a new, empty resource cell.
sourcepub fn new(data: T) -> AtomicResource<T>
pub fn new(data: T) -> AtomicResource<T>
Create a new resource cell with the given data.
sourcepub fn from_untyped(
untyped: Arc<UntypedResource>,
) -> Result<AtomicResource<T>, SchemaMismatchError>
pub fn from_untyped( untyped: Arc<UntypedResource>, ) -> Result<AtomicResource<T>, SchemaMismatchError>
Create from an UntypedResource
.
sourcepub fn borrow(&self) -> Option<Ref<'_, T>>
pub fn borrow(&self) -> Option<Ref<'_, T>>
Lock the resource for reading.
This returns a read guard, very similar to an RwLock
.
sourcepub fn borrow_mut(&self) -> Option<RefMut<'_, T>>
pub fn borrow_mut(&self) -> Option<RefMut<'_, T>>
Lock the resource for read-writing.
This returns a write guard, very similar to an RwLock
.
sourcepub fn into_untyped(self) -> Arc<UntypedResource>
pub fn into_untyped(self) -> Arc<UntypedResource>
Convert into an untyped resource.
source§impl<T> AtomicResource<T>
impl<T> AtomicResource<T>
sourcepub fn init(&self, world: &World)
pub fn init(&self, world: &World)
Initialize the resource using it’s FromWorld
implementation, if it is not present.
sourcepub fn init_borrow(&self, world: &World) -> Ref<'_, T>
pub fn init_borrow(&self, world: &World) -> Ref<'_, T>
Borrow the resource, initializing it if it doesn’t exist.
sourcepub fn init_borrow_mut(&self, world: &World) -> RefMut<'_, T>
pub fn init_borrow_mut(&self, world: &World) -> RefMut<'_, T>
Borrow the resource, initializing it if it doesn’t exist.
Trait Implementations§
source§impl<T> Clone for AtomicResource<T>
impl<T> Clone for AtomicResource<T>
source§fn clone(&self) -> AtomicResource<T>
fn clone(&self) -> AtomicResource<T>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<T> Debug for AtomicResource<T>
impl<T> Debug for AtomicResource<T>
Auto Trait Implementations§
impl<T> Freeze for AtomicResource<T>
impl<T> !RefUnwindSafe for AtomicResource<T>
impl<T> Send for AtomicResource<T>
impl<T> Sync for AtomicResource<T>
impl<T> Unpin for AtomicResource<T>where
T: Unpin,
impl<T> !UnwindSafe for AtomicResource<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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
source§fn from_world(_world: &World) -> T
fn from_world(_world: &World) -> T
Creates
Self
using data from the given World
.