Struct bones_lib::prelude::AtomicResource
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§
§impl<T> AtomicResource<T>where
T: HasSchema,
impl<T> AtomicResource<T>where
T: HasSchema,
pub fn empty() -> AtomicResource<T>
pub fn empty() -> AtomicResource<T>
Create a new, empty resource cell.
pub fn new(data: T) -> AtomicResource<T>
pub fn new(data: T) -> AtomicResource<T>
Create a new resource cell with the given data.
pub 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
.
pub 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
.
pub 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
.
pub fn into_untyped(self) -> Arc<UntypedResource>
pub fn into_untyped(self) -> Arc<UntypedResource>
Convert into an untyped resource.
§impl<T> AtomicResource<T>
impl<T> AtomicResource<T>
pub fn init(&self, world: &World)
pub fn init(&self, world: &World)
Initialize the resource using it’s FromWorld
implementation, if it is not present.
pub 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.
pub 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§
§impl<T> Clone for AtomicResource<T>
impl<T> Clone for AtomicResource<T>
§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 more§impl<T> Debug for AtomicResource<T>
impl<T> Debug for AtomicResource<T>
§impl<T> Default for AtomicResource<T>
impl<T> Default for AtomicResource<T>
§fn default() -> AtomicResource<T>
fn default() -> AtomicResource<T>
Returns the “default value” for a type. Read more
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
)§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
§fn from_world(_world: &World) -> T
fn from_world(_world: &World) -> T
Creates
Self
using data from the given World
.