Enum fyrox_resource::ResourceState
source · [−]pub enum ResourceState<T, E> where
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
Fields
path: PathBufA path to load resource from.
Resource is loading from external resource or in the queue to load.
LoadError
Fields
path: PathBufA path at which it was impossible to load the resource.
An error has occurred during the load.
Ok(T)
Actual resource data when it is fully loaded.
Implementations
sourceimpl<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 switch_to_pending_state(&mut self)
pub fn switch_to_pending_state(&mut self)
Switches the internal state of the resource to ResourceState::Pending.
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.
sourcepub fn commit_ok(&mut self, data: T)
pub fn commit_ok(&mut self, data: T)
Changes internal state to ResourceState::Ok
sourcepub fn commit_error(&mut self, path: PathBuf, error: E)
pub fn commit_error(&mut self, path: PathBuf, error: E)
Changes internal state to ResourceState::LoadError.
Trait Implementations
sourceimpl<T: Debug, E: Debug> Debug for ResourceState<T, E> where
T: ResourceData,
E: ResourceLoadError,
impl<T: Debug, E: Debug> Debug for ResourceState<T, E> where
T: ResourceData,
E: ResourceLoadError,
sourceimpl<T: ResourceData, E: ResourceLoadError> Default for ResourceState<T, E>
impl<T: ResourceData, E: ResourceLoadError> Default for ResourceState<T, E>
sourceimpl<T, E> Visit for ResourceState<T, E> where
T: ResourceData,
E: ResourceLoadError,
impl<T, E> Visit for ResourceState<T, E> where
T: ResourceData,
E: ResourceLoadError,
fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult
Auto Trait Implementations
impl<T, E> RefUnwindSafe for ResourceState<T, E> where
E: RefUnwindSafe,
T: 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
E: RefUnwindSafe,
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> PropertyValue for T where
T: 'static + Debug,
impl<T> PropertyValue for T where
T: 'static + Debug,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
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 more
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).
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.
fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts self to the equivalent element of its superset.