ResourceState

Enum ResourceState 

Source
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

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

Fields

§path: PathBuf

A path to load resource from.

§wakers: Vec<Waker>

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

§

LoadError

An error has occurred during the load.

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.

§

Ok(T)

Actual resource data when it is fully loaded.

Implementations§

Source§

impl<T: ResourceData, E: ResourceLoadError> ResourceState<T, E>

Source

pub fn new_pending(path: PathBuf) -> Self

Creates new resource in pending state.

Source

pub fn path(&self) -> Cow<'_, Path>

Returns a path to the resource source.

Source

pub fn commit(&mut self, state: ResourceState<T, E>)

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

Trait Implementations§

Source§

impl<T: Debug + ResourceData, E: Debug + ResourceLoadError> Debug for ResourceState<T, E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ResourceData, E: ResourceLoadError> Default for ResourceState<T, E>

Source§

fn default() -> Self

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

impl<T: ResourceData, E: ResourceLoadError> Visit for ResourceState<T, E>

Source§

fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult

Auto Trait Implementations§

§

impl<T, E> Freeze for ResourceState<T, E>
where T: Freeze,

§

impl<T, E> RefUnwindSafe for ResourceState<T, E>

§

impl<T, E> Send for ResourceState<T, E>

§

impl<T, E> Sync for ResourceState<T, E>
where T: Sync,

§

impl<T, E> Unpin for ResourceState<T, E>
where T: Unpin,

§

impl<T, E> UnwindSafe for ResourceState<T, E>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> PropertyValue for T
where T: Debug + 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Casts self to a &dyn Any
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

fn from_subset(element: &SS) -> SP

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ResourceLoadError for T
where T: 'static + Debug + Send + Sync,