Struct bones_ecs::resources::UntypedResource
source · pub struct UntypedResource { /* private fields */ }
Expand description
An untyped resource that may be inserted into UntypedResources
.
This is fundamentally a Arc<AtomicCell<Option<SchemaBox>>>
and thus represents
a cell that may or may not contain a resource of it’s schema.
Implementations§
source§impl UntypedResource
impl UntypedResource
sourcepub fn empty(schema: &'static Schema) -> Self
pub fn empty(schema: &'static Schema) -> Self
Initialize a new, empty UntypedResource
.
sourcepub fn new(resource: SchemaBox) -> Self
pub fn new(resource: SchemaBox) -> Self
Creates a new UntypedResource
storing the given data.
sourcepub fn from_default(schema: &'static Schema) -> Self
pub fn from_default(schema: &'static Schema) -> Self
Create a new UntypedResource
for the given schema, initially populated with the default
value for the schema.
sourcepub fn clone_data(&self) -> Option<SchemaBox>
pub fn clone_data(&self) -> Option<SchemaBox>
Clone the inner data, creating a new copy instead of returning another handle the the same
data, as the normal clone()
implementation does.
sourcepub fn insert(
&self,
data: SchemaBox,
) -> Result<Option<SchemaBox>, SchemaMismatchError>
pub fn insert( &self, data: SchemaBox, ) -> Result<Option<SchemaBox>, SchemaMismatchError>
Insert resource data into the cell, returning the previous data.
§Errors
Errors if the schema of the data does not match that of this cell.
sourcepub fn remove(&self) -> Option<SchemaBox>
pub fn remove(&self) -> Option<SchemaBox>
Remove the resource data, returning what was stored in it.
sourcepub fn borrow_mut(&self) -> RefMut<'_, Option<SchemaBox>>
pub fn borrow_mut(&self) -> RefMut<'_, Option<SchemaBox>>
Mutably borrow the resource.