Struct keeshond_datapack::DataHandle
source · [−]pub struct DataHandle<T: DataObject + 'static> { /* private fields */ }
Expand description
A path to a data resource, resolvable to a cached DataId.
This object serves three purposes:
- Conveniently resolving a path to an ID but only when resolution is necessary
- Serializing data that needs to reference a DataObject
- Keeping a package open so it doesn’t get auto-unloaded.
If placing inside a DataObject struct, take care not to have a self-referencing type (i.e. a DataHandle<T> inside a T) or a type cycle (i.e. a DataHandle<T> inside a U and a DataHandle<U> inside a T). Otherwise the auto-unload mechanism may not be able to unload the package the object is from.
Implementations
sourceimpl<T: DataObject + 'static> DataHandle<T>
impl<T: DataObject + 'static> DataHandle<T>
sourcepub fn null() -> DataHandle<T>
pub fn null() -> DataHandle<T>
Creates a new DataHandle that points to nothing. Resolving this data handle will fail until it is given a valid path, such as through set_path().
sourcepub fn with_path(package: &str, path: &str) -> DataHandle<T>
pub fn with_path(package: &str, path: &str) -> DataHandle<T>
Creates a new DataHandle with the given resource path. The data ID will be unresolved. You will need to call resolve() for the data ID to point to a valid resource.
sourcepub fn clone_without_path(&self) -> DataHandle<T>
pub fn clone_without_path(&self) -> DataHandle<T>
Clones the given DataHandle but only retains the ID, erasing the path. This is useful for instances where you want to store a lot of handles but don’t need the path, to cut down on memory usage.
sourcepub fn set_path(&mut self, package: &str, path: &str)
pub fn set_path(&mut self, package: &str, path: &str)
Changes the resource path. The data ID will reset to be unresolved. You will need to call resolve() for the data ID to point to a valid resource.
sourcepub fn id(&self) -> DataId<T>
pub fn id(&self) -> DataId<T>
Returns the data ID. You will need to call resolve() beforehand for the data ID to point to a valid resource.
sourcepub fn resolved(&self) -> bool
pub fn resolved(&self) -> bool
Returns true if the path has been resolved via a call to resolve().
sourcepub fn resolve(
&self,
data_res: &mut DataStore<T>,
load_error: LoadErrorMode
) -> DataId<T>
pub fn resolve(
&self,
data_res: &mut DataStore<T>,
load_error: LoadErrorMode
) -> DataId<T>
Resolves the data ID using the given DataStore. Returns the resolved data ID, which is cached inside the object. If load_error is Fatal, this function will panic if the load fails. Otherwise it will simply return a null data ID.
sourcepub fn get<'a, 'b: 'a>(
&self,
data_res: &'b mut DataStore<T>,
load_error: LoadErrorMode
) -> Option<&'a T>
pub fn get<'a, 'b: 'a>(
&self,
data_res: &'b mut DataStore<T>,
load_error: LoadErrorMode
) -> Option<&'a T>
Returns a reference to data object in the store, if it exists. If the data object is not resolved, then resolve() will be called, and then the data object reference returned, if available.
sourcepub fn get_mut<'a, 'b: 'a>(
&self,
data_res: &'b mut DataStore<T>,
load_error: LoadErrorMode
) -> Option<&'a mut T>
pub fn get_mut<'a, 'b: 'a>(
&self,
data_res: &'b mut DataStore<T>,
load_error: LoadErrorMode
) -> Option<&'a mut T>
Returns a mutable reference to data object in the store, if it exists. If the data object is not resolved, then resolve() will be called, and then the data object reference returned, if available.
sourcepub fn get_if_resolved<'a, 'b: 'a>(
&self,
data_res: &'b DataStore<T>
) -> Option<&'a T>
pub fn get_if_resolved<'a, 'b: 'a>(
&self,
data_res: &'b DataStore<T>
) -> Option<&'a T>
Returns a reference to data object in the store, if it exists. If the data object is not resolved, returns None instead of attempting to resolve.
sourcepub fn get_mut_if_resolved<'a, 'b: 'a>(
&self,
data_res: &'b mut DataStore<T>
) -> Option<&'a mut T>
pub fn get_mut_if_resolved<'a, 'b: 'a>(
&self,
data_res: &'b mut DataStore<T>
) -> Option<&'a mut T>
Returns a mutable reference to data object in the store, if it exists. If the data object is not resolved, returns None instead of attempting to resolve.
sourcepub fn resolve_if_loaded(&self, data_res: &DataStore<T>) -> DataId<T>
pub fn resolve_if_loaded(&self, data_res: &DataStore<T>) -> DataId<T>
Resolves the data ID using the given DataStore. Returns the resolved data ID, which is cached inside the object. If the data is not yet loaded, returns a null ID.
Trait Implementations
sourceimpl<T: DataObject + 'static> Clone for DataHandle<T>
impl<T: DataObject + 'static> Clone for DataHandle<T>
sourceimpl<T: DataObject + 'static> Debug for DataHandle<T>
impl<T: DataObject + 'static> Debug for DataHandle<T>
sourceimpl<T: DataObject + 'static> Default for DataHandle<T>
impl<T: DataObject + 'static> Default for DataHandle<T>
Auto Trait Implementations
impl<T> !RefUnwindSafe for DataHandle<T>
impl<T> !Send for DataHandle<T>
impl<T> !Sync for DataHandle<T>
impl<T> Unpin for DataHandle<T> where
T: Unpin,
impl<T> UnwindSafe for DataHandle<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
sourcefn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
sourcefn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
sourcefn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
sourcefn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more