Enum fyrox::asset::state::ResourceState
source · pub enum ResourceState {
Pending {
path: PathBuf,
wakers: Vec<Waker>,
type_uuid: Uuid,
},
LoadError {
path: PathBuf,
error: Option<Arc<dyn ResourceLoadError>>,
type_uuid: Uuid,
},
Ok(Box<dyn ResourceData>),
}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
Resource is loading from external resource or in the queue to load.
LoadError
Fields
error: Option<Arc<dyn ResourceLoadError>>An error. This wrapped in Option only to be Default_ed.
An error has occurred during the load.
Ok(Box<dyn ResourceData>)
Actual resource data when it is fully loaded.
Implementations§
source§impl ResourceState
impl ResourceState
sourcepub fn new_pending(path: PathBuf, type_uuid: Uuid) -> ResourceState
pub fn new_pending(path: PathBuf, type_uuid: Uuid) -> ResourceState
Creates new resource in pending state.
sourcepub fn new_load_error(
path: PathBuf,
error: Option<Arc<dyn ResourceLoadError>>,
type_uuid: Uuid
) -> ResourceState
pub fn new_load_error( path: PathBuf, error: Option<Arc<dyn ResourceLoadError>>, type_uuid: Uuid ) -> ResourceState
Creates new resource in error state.
sourcepub fn new_ok<T>(data: T) -> ResourceStatewhere
T: ResourceData,
pub fn new_ok<T>(data: T) -> ResourceStatewhere T: ResourceData,
Creates new resource in ok (resource with data) state.
sourcepub fn is_loading(&self) -> bool
pub fn is_loading(&self) -> bool
Checks whether the resource is still loading or not.
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)
pub fn commit(&mut self, state: ResourceState)
Changes ResourceState::Pending state to ResourceState::Ok(data) with given data.
Additionally it wakes all futures.
sourcepub fn commit_ok<T>(&mut self, data: T)where
T: ResourceData,
pub fn commit_ok<T>(&mut self, data: T)where T: ResourceData,
Changes internal state to ResourceState::Ok
sourcepub fn commit_error<E>(&mut self, path: PathBuf, error: E)where
E: ResourceLoadError,
pub fn commit_error<E>(&mut self, path: PathBuf, error: E)where E: ResourceLoadError,
Changes internal state to ResourceState::LoadError.
Trait Implementations§
source§impl Debug for ResourceState
impl Debug for ResourceState
source§impl Default for ResourceState
impl Default for ResourceState
source§fn default() -> ResourceState
fn default() -> ResourceState
source§impl Drop for ResourceState
impl Drop for ResourceState
Auto Trait Implementations§
impl !RefUnwindSafe for ResourceState
impl Send for ResourceState
impl !Sync for ResourceState
impl Unpin for ResourceState
impl !UnwindSafe for ResourceState
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.source§impl<T> FieldValue for Twhere
T: 'static,
impl<T> FieldValue for Twhere T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> ScriptMessagePayload for Twhere
T: 'static + Send,
impl<T> ScriptMessagePayload for Twhere T: 'static + Send,
source§fn as_any_ref(&self) -> &(dyn Any + 'static)
fn as_any_ref(&self) -> &(dyn Any + 'static)
self as &dyn Anysource§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
self as &dyn Any§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
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
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.