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:
- Pending - it is loading.
- LoadError - an error has occurred during the load.
- 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
LoadError
An error has occurred during the load.
Fields
Ok(T)
Actual resource data when it is fully loaded.
Implementations§
Source§impl<T: ResourceData, E: ResourceLoadError> ResourceState<T, E>
impl<T: ResourceData, E: ResourceLoadError> ResourceState<T, E>
Sourcepub fn new_pending(path: PathBuf) -> Self
pub fn new_pending(path: PathBuf) -> Self
Creates new resource in pending state.
Sourcepub fn commit(&mut self, state: ResourceState<T, E>)
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>
impl<T: Debug + ResourceData, E: Debug + ResourceLoadError> Debug for ResourceState<T, E>
Source§impl<T: ResourceData, E: ResourceLoadError> Default for ResourceState<T, E>
impl<T: ResourceData, E: ResourceLoadError> Default for ResourceState<T, E>
Source§impl<T: ResourceData, E: ResourceLoadError> Visit for ResourceState<T, E>
impl<T: ResourceData, E: ResourceLoadError> Visit for ResourceState<T, E>
Auto Trait Implementations§
impl<T, E> Freeze for ResourceState<T, E>where
T: Freeze,
impl<T, E> RefUnwindSafe for ResourceState<T, E>where
T: RefUnwindSafe,
E: RefUnwindSafe,
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>where
T: UnwindSafe,
E: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> PropertyValue for Twhere
T: Debug + 'static,
impl<T> PropertyValue for Twhere
T: Debug + 'static,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.