Enum rg3d_resource::ResourceState[][src]

pub enum ResourceState<T: ResourceData, E: ResourceLoadError> {
    Pending {
        path: PathBuf,
        wakers: Vec<Waker>,
    },
    LoadError {
        path: PathBuf,
        error: Option<Arc<E>>,
    },
    Ok(T),
}
Expand description

Resource could be in three possible states:

  1. Pending - it is loading.
  2. LoadError - an error has occurred during the load.
  3. Ok - resource is fully loaded and ready to use.

Why it is so complex? Short answer: asynchronous loading. Long answer: when you loading a scene you expect it to be loaded as fast as possible, use all available power of the CPU. To achieve that each resource ideally should be loaded on separate core of the CPU, but since this is asynchronous, we must have the ability to track the state of the resource.

Variants

Pending

Fields

path: PathBuf

A path to load resource from.

wakers: Vec<Waker>

List of wakers to wake future when resource is fully loaded.

Resource is loading from external resource or in the queue to load.

LoadError

Fields

path: PathBuf

A path at which it was impossible to load the resource.

error: Option<Arc<E>>

An error. This wrapped in Option only to be Default_ed.

An error has occurred during the load.

Ok(T)

Tuple Fields

0: T

Actual resource data when it is fully loaded.

Implementations

Creates new resource in pending state.

Returns a path to the resource source.

Changes ResourceState::Pending state to ResourceState::Ok(data) with given data. Additionally it wakes all futures.

Trait Implementations

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

Performs the conversion.

Performs the conversion.

Casts self to a &dyn Any

Should always be Self

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more

Checks if self is actually part of its subset T (and can be converted to it).

Use with care! Same as self.to_subset but without any property checks. Always succeeds.

The inclusion map: converts self to the equivalent element of its superset.

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.