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

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().

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.

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.

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.

Returns the package name part of the resource path

Returns the filepath to the resource

Returns the data ID. You will need to call resolve() beforehand for the data ID to point to a valid resource.

Returns true if the path has been resolved via a call to resolve().

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.

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.

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.

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.

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.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

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

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

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.