pub struct Resource<T: Debug> { /* private fields */ }Expand description
A resource of particular data type. It is a typed wrapper around UntypedResource which
does type checks at runtime. See UntypedResource for more info.
§Default State
Default state of the resource will be ResourceState::Ok with T::default.
Implementations§
Source§impl<T> Resource<T>where
T: TypedResourceData,
impl<T> Resource<T>where
T: TypedResourceData,
Sourcepub fn summary(&self) -> String
pub fn summary(&self) -> String
Create a summary of this resource handle, wht UUID, embedded/external, and Ok, Pending, Error, etc.
Sourcepub fn new_pending(uuid: Uuid, kind: ResourceKind) -> Self
pub fn new_pending(uuid: Uuid, kind: ResourceKind) -> Self
Creates new resource in pending state.
Sourcepub fn new_ok(resource_uuid: Uuid, kind: ResourceKind, data: T) -> Self
pub fn new_ok(resource_uuid: Uuid, kind: ResourceKind, data: T) -> Self
Creates new resource in ok state (fully loaded).
Sourcepub fn new_embedded(data: T) -> Self
pub fn new_embedded(data: T) -> Self
Creates a new embedded resource in ok state (fully loaded).
Sourcepub fn new_load_error(
kind: ResourceKind,
path: PathBuf,
error: LoadError,
) -> Self
pub fn new_load_error( kind: ResourceKind, path: PathBuf, error: LoadError, ) -> Self
Creates new resource in error state.
Sourcepub fn into_untyped(self) -> UntypedResource ⓘ
pub fn into_untyped(self) -> UntypedResource ⓘ
Converts self to internal value.
Sourcepub fn state(&self) -> ResourceHeaderGuard<'_, T>
pub fn state(&self) -> ResourceHeaderGuard<'_, T>
Locks internal mutex provides access to the state.
Sourcepub fn try_acquire_state(&self) -> Option<ResourceHeaderGuard<'_, T>>
pub fn try_acquire_state(&self) -> Option<ResourceHeaderGuard<'_, T>>
Tries to lock internal mutex provides access to the state.
Sourcepub fn header(&self) -> MutexGuard<'_, ResourceHeader>
pub fn header(&self) -> MutexGuard<'_, ResourceHeader>
Locks the resource and provides access to its header. See ResourceHeader docs for more info.
Sourcepub fn is_loading(&self) -> bool
pub fn is_loading(&self) -> bool
Returns true if the resource is still loading.
Sourcepub fn is_failed_to_load(&self) -> bool
pub fn is_failed_to_load(&self) -> bool
Returns true if the resource is failed to load.
Sourcepub fn kind(&self) -> ResourceKind
pub fn kind(&self) -> ResourceKind
Returns kind of the resource, if the resource is registered.
Sourcepub fn resource_uuid(&self) -> Uuid
pub fn resource_uuid(&self) -> Uuid
The UUID of the resource. All resources must have a UUID, even if they are not loaded because the UUID is how the resource manager knows the path to load from.
Sourcepub fn set_path(&mut self, new_kind: ResourceKind)
pub fn set_path(&mut self, new_kind: ResourceKind)
Sets a new kind of the resource.
Sourcepub fn data_ref(&self) -> ResourceDataRef<'_, T>
pub fn data_ref(&self) -> ResourceDataRef<'_, T>
Allows you to get a reference to the resource data. The returned object implements Deref
and DerefMut traits, and basically acts like a reference to the resource value.
§Panic
An attempt to dereference the returned object will result in panic if the resource is not
loaded yet, or there was a loading error. Usually this is ok because you should chain this
call like this resource.await?.data_ref(). Every resource implements Future trait,
and it returns Result, so if you’ll await the future then you’ll get Result, so call to
data_ref will be fine.
You can also use [ResourceDataRef::as_loaded_ref] and [ResourceDataRef::as_loaded_mut]
methods that perform checked access to the resource internals.
Trait Implementations§
Source§impl<T: TypedResourceData> AsRef<UntypedResource> for Resource<T>
impl<T: TypedResourceData> AsRef<UntypedResource> for Resource<T>
Source§fn as_ref(&self) -> &UntypedResource ⓘ
fn as_ref(&self) -> &UntypedResource ⓘ
Source§impl<T> Default for Resource<T>where
T: TypedResourceData,
impl<T> Default for Resource<T>where
T: TypedResourceData,
Source§impl<'de, T> Deserialize<'de> for Resource<T>where
T: TypedResourceData + Debug,
impl<'de, T> Deserialize<'de> for Resource<T>where
T: TypedResourceData + Debug,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<T> From<UntypedResource> for Resource<T>where
T: TypedResourceData,
impl<T> From<UntypedResource> for Resource<T>where
T: TypedResourceData,
Source§fn from(untyped: UntypedResource) -> Self
fn from(untyped: UntypedResource) -> Self
Source§impl<T> Future for Resource<T>where
T: TypedResourceData,
impl<T> Future for Resource<T>where
T: TypedResourceData,
Source§impl<T> Hash for Resource<T>where
T: TypedResourceData,
impl<T> Hash for Resource<T>where
T: TypedResourceData,
Source§impl<T> Into<UntypedResource> for Resource<T>where
T: TypedResourceData,
impl<T> Into<UntypedResource> for Resource<T>where
T: TypedResourceData,
Source§fn into(self) -> UntypedResource ⓘ
fn into(self) -> UntypedResource ⓘ
Source§impl<T> PartialEq for Resource<T>where
T: TypedResourceData,
impl<T> PartialEq for Resource<T>where
T: TypedResourceData,
Source§impl<T: Debug> Reflect for Resource<T>where
Self: 'static,
impl<T: Debug> Reflect for Resource<T>where
Self: 'static,
fn source_path() -> &'static str
fn try_clone_box(&self) -> Option<Box<dyn Reflect>>
fn type_name(&self) -> &'static str
fn derived_types() -> &'static [TypeId]
fn query_derived_types(&self) -> &'static [TypeId]
fn doc(&self) -> &'static str
Source§fn assembly_name(&self) -> &'static str
fn assembly_name(&self) -> &'static str
#[derive(Reflect)]) to ensure that this method will return correct assembly
name. In other words - there’s no guarantee, that any implementation other than proc-macro
will return a correct name of the assembly. Alternatively, you can use env!("CARGO_PKG_NAME")
as an implementation.Source§fn type_assembly_name() -> &'static str
fn type_assembly_name() -> &'static str
#[derive(Reflect)]) to ensure that this method will return correct assembly
name. In other words - there’s no guarantee, that any implementation other than proc-macro
will return a correct name of the assembly. Alternatively, you can use env!("CARGO_PKG_NAME")
as an implementation.fn fields_ref(&self, func: &mut dyn FnMut(&[FieldRef<'_, '_>]))
fn fields_mut(&mut self, func: &mut dyn FnMut(&mut [FieldMut<'_, '_>]))
fn into_any(self: Box<Self>) -> Box<dyn Any>
fn set( &mut self, value: Box<dyn Reflect>, ) -> Result<Box<dyn Reflect>, Box<dyn Reflect>>
fn as_any(&self, func: &mut dyn FnMut(&dyn Any))
fn as_any_mut(&mut self, func: &mut dyn FnMut(&mut dyn Any))
fn as_reflect(&self, func: &mut dyn FnMut(&dyn Reflect))
fn as_reflect_mut(&mut self, func: &mut dyn FnMut(&mut dyn Reflect))
Source§fn set_field(
&mut self,
field_name: &str,
value: Box<dyn Reflect>,
func: &mut dyn FnMut(Result<Box<dyn Reflect>, SetFieldError>),
)
fn set_field( &mut self, field_name: &str, value: Box<dyn Reflect>, func: &mut dyn FnMut(Result<Box<dyn Reflect>, SetFieldError>), )
#[reflect(setter = ..)] or falls back to
Reflect::field_mutfn field( &self, name: &str, func: &mut dyn FnMut(Option<&(dyn Reflect + 'static)>), )
fn field_mut( &mut self, name: &str, func: &mut dyn FnMut(Option<&mut (dyn Reflect + 'static)>), )
fn as_array(&self, func: &mut dyn FnMut(Option<&(dyn ReflectArray + 'static)>))
fn as_array_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectArray + 'static)>), )
fn as_list(&self, func: &mut dyn FnMut(Option<&(dyn ReflectList + 'static)>))
fn as_list_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectList + 'static)>), )
fn as_inheritable_variable( &self, func: &mut dyn FnMut(Option<&(dyn ReflectInheritableVariable + 'static)>), )
fn as_inheritable_variable_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectInheritableVariable + 'static)>), )
fn as_hash_map( &self, func: &mut dyn FnMut(Option<&(dyn ReflectHashMap + 'static)>), )
fn as_hash_map_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectHashMap + 'static)>), )
fn as_handle( &self, func: &mut dyn FnMut(Option<&(dyn ReflectHandle + 'static)>), )
fn as_handle_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectHandle + 'static)>), )
Source§impl<T: TypedResourceData> TypeUuidProvider for Resource<T>
impl<T: TypedResourceData> TypeUuidProvider for Resource<T>
Source§impl<T> Visit for Resource<T>where
T: TypedResourceData,
impl<T> Visit for Resource<T>where
T: TypedResourceData,
Source§fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult
fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult
impl<T> Eq for Resource<T>where
T: TypedResourceData,
Auto Trait Implementations§
impl<T> Freeze for Resource<T>
impl<T> !RefUnwindSafe for Resource<T>
impl<T> Send for Resource<T>where
T: Send,
impl<T> Sync for Resource<T>where
T: Sync,
impl<T> Unpin for Resource<T>where
T: Unpin,
impl<T> UnsafeUnpin for Resource<T>
impl<T> !UnwindSafe for Resource<T>
Blanket Implementations§
Source§impl<T> AsyncTaskResult for T
impl<T> AsyncTaskResult for T
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FieldValue for Twhere
T: Reflect,
impl<T> FieldValue for Twhere
T: Reflect,
Source§fn field_value_as_any_ref(&self) -> &(dyn Any + 'static)
fn field_value_as_any_ref(&self) -> &(dyn Any + 'static)
self to a &dyn AnySource§fn field_value_as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn field_value_as_any_mut(&mut self) -> &mut (dyn Any + 'static)
self to a &mut dyn Anyfn field_value_as_reflect(&self) -> &(dyn Reflect + 'static)
fn field_value_as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
fn type_name(&self) -> &'static str
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn map<U, F>(self, f: F) -> Map<Self, F>
fn map<U, F>(self, f: F) -> Map<Self, F>
Source§fn map_into<U>(self) -> MapInto<Self, U>
fn map_into<U>(self) -> MapInto<Self, U>
Source§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
f. Read moreSource§fn left_future<B>(self) -> Either<Self, B>
fn left_future<B>(self) -> Either<Self, B>
Source§fn right_future<A>(self) -> Either<A, Self>
fn right_future<A>(self) -> Either<A, Self>
Source§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
Source§fn flatten(self) -> Flatten<Self>
fn flatten(self) -> Flatten<Self>
Source§fn flatten_stream(self) -> FlattenStream<Self>
fn flatten_stream(self) -> FlattenStream<Self>
Source§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
poll will never again be called once it has
completed. This method can be used to turn any Future into a
FusedFuture. Read moreSource§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
Source§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
Source§fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
() on completion and sends
its output to another future on a separate task. Read moreSource§fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
Source§fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
Source§fn unit_error(self) -> UnitError<Self>where
Self: Sized,
fn unit_error(self) -> UnitError<Self>where
Self: Sized,
Future<Output = T> into a
TryFuture<Ok = T, Error = ()>.Source§fn never_error(self) -> NeverError<Self>where
Self: Sized,
fn never_error(self) -> NeverError<Self>where
Self: Sized,
Future<Output = T> into a
TryFuture<Ok = T, Error = Never>.Source§impl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
Source§type IntoFuture = F
type IntoFuture = F
Source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Source§impl<T, U> ObjectOrVariant<T> for Uwhere
PhantomData<U>: ObjectOrVariantHelper<T, U>,
impl<T, U> ObjectOrVariant<T> for Uwhere
PhantomData<U>: ObjectOrVariantHelper<T, U>,
Source§impl<T> ReflectBase for Twhere
T: Reflect,
impl<T> ReflectBase for Twhere
T: Reflect,
fn as_any_raw(&self) -> &(dyn Any + 'static)
fn as_any_raw_mut(&mut self) -> &mut (dyn Any + 'static)
Source§impl<T> ResolvePath for Twhere
T: Reflect,
impl<T> ResolvePath for Twhere
T: Reflect,
fn resolve_path<'p>( &self, path: &'p str, func: &mut dyn FnMut(Result<&(dyn Reflect + 'static), ReflectPathError<'p>>), )
fn resolve_path_mut<'p>( &mut self, path: &'p str, func: &mut dyn FnMut(Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>), )
fn get_resolve_path<'p, T>(
&self,
path: &'p str,
func: &mut dyn FnMut(Result<&T, ReflectPathError<'p>>),
)where
T: Reflect,
fn get_resolve_path_mut<'p, T>(
&mut self,
path: &'p str,
func: &mut dyn FnMut(Result<&mut T, ReflectPathError<'p>>),
)where
T: Reflect,
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>
self from the equivalent element of its
superset. Read moreSource§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).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.