pub struct Resource<T>where
T: TypedResourceData,{ /* 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,
Source§impl<T> Resource<T>where
T: TypedResourceData,
impl<T> Resource<T>where
T: TypedResourceData,
Sourcepub fn new_pending(kind: ResourceKind) -> Resource<T> ⓘ
pub fn new_pending(kind: ResourceKind) -> Resource<T> ⓘ
Creates new resource in pending state.
Sourcepub fn new_ok(kind: ResourceKind, data: T) -> Resource<T> ⓘ
pub fn new_ok(kind: ResourceKind, data: T) -> Resource<T> ⓘ
Creates new resource in ok state (fully loaded).
Sourcepub fn new_load_error(kind: ResourceKind, error: LoadError) -> Resource<T> ⓘ
pub fn new_load_error(kind: ResourceKind, error: LoadError) -> Resource<T> ⓘ
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.
pub fn header(&self) -> MutexGuard<'_, RawMutex, ResourceHeader>
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.
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 obtain reference to the resource data.
§Panic
An attempt to use method result will panic if resource is not loaded yet, or
there was load error. Usually this is ok because normally you’d chain this call
like this resource.await?.data_ref()
. Every resource implements Future trait
and it returns Result, so if you’ll await future then you’ll get Result, so
call to data_ref
will be fine.
Trait Implementations§
Source§impl<T> Clone for Resource<T>where
T: TypedResourceData,
impl<T> Clone for Resource<T>where
T: TypedResourceData,
Source§impl<T> Default for Resource<T>where
T: TypedResourceData,
impl<T> Default for Resource<T>where
T: TypedResourceData,
Source§impl From<Resource<Texture>> for MaterialResourceBinding
impl From<Resource<Texture>> for MaterialResourceBinding
Source§fn from(value: TextureResource) -> Self
fn from(value: TextureResource) -> Self
Source§impl<T> From<UntypedResource> for Resource<T>where
T: TypedResourceData,
impl<T> From<UntypedResource> for Resource<T>where
T: TypedResourceData,
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 HrirSphereResourceExt for Resource<HrirSphereResourceData>
impl HrirSphereResourceExt for Resource<HrirSphereResourceData>
Source§fn from_hrir_sphere(
hrir_sphere: HrirSphere,
kind: ResourceKind,
) -> Resource<HrirSphereResourceData> ⓘ
fn from_hrir_sphere( hrir_sphere: HrirSphere, kind: ResourceKind, ) -> Resource<HrirSphereResourceData> ⓘ
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 IntoPrimitive<Resource<Texture>> for StyleProperty
impl IntoPrimitive<Resource<Texture>> for StyleProperty
Source§impl<T> PartialEq for Resource<T>where
T: TypedResourceData,
impl<T> PartialEq for Resource<T>where
T: TypedResourceData,
Source§impl<T> Reflect for Resource<T>
impl<T> Reflect for Resource<T>
fn source_path() -> &'static str
fn type_name(&self) -> &'static str
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_info(&self, func: &mut dyn FnMut(&[FieldInfo<'_, '_>]))
fn into_any(self: Box<Resource<T>>) -> 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 + 'static)))
fn as_any_mut(&mut self, func: &mut dyn FnMut(&mut (dyn Any + 'static)))
fn as_reflect(&self, func: &mut dyn FnMut(&(dyn Reflect + 'static)))
fn as_reflect_mut(&mut self, func: &mut dyn FnMut(&mut (dyn Reflect + 'static)))
fn fields(&self, func: &mut dyn FnMut(&[&(dyn Reflect + 'static)]))
fn fields_mut( &mut self, func: &mut dyn FnMut(&mut [&mut (dyn Reflect + 'static)]), )
fn 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)>), )
Source§fn set_field(
&mut self,
field: &str,
value: Box<dyn Reflect>,
func: &mut dyn FnMut(Result<Box<dyn Reflect>, Box<dyn Reflect>>),
)
fn set_field( &mut self, field: &str, value: Box<dyn Reflect>, func: &mut dyn FnMut(Result<Box<dyn Reflect>, Box<dyn Reflect>>), )
#[reflect(setter = ..)]
or falls back to
Reflect::field_mut
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)>), )
Source§impl SoundBufferResourceExtension for Resource<SoundBuffer>
impl SoundBufferResourceExtension for Resource<SoundBuffer>
Source§fn new_streaming(
data_source: DataSource,
) -> Result<Resource<SoundBuffer>, DataSource>
fn new_streaming( data_source: DataSource, ) -> Result<Resource<SoundBuffer>, DataSource>
Source§fn new_generic(
data_source: DataSource,
) -> Result<Resource<SoundBuffer>, DataSource>
fn new_generic( data_source: DataSource, ) -> Result<Resource<SoundBuffer>, DataSource>
Source§impl StyleResourceExt for Resource<Style>
impl StyleResourceExt for Resource<Style>
Source§fn set(
&self,
name: impl Into<ImmutableString>,
property: impl Into<StyleProperty>,
)
fn set( &self, name: impl Into<ImmutableString>, property: impl Into<StyleProperty>, )
Style::set
.Source§fn get<P>(&self, name: impl Into<ImmutableString>) -> Option<P>where
StyleProperty: IntoPrimitive<P>,
fn get<P>(&self, name: impl Into<ImmutableString>) -> Option<P>where
StyleProperty: IntoPrimitive<P>,
Style::get
.Source§fn get_or<P>(&self, name: impl Into<ImmutableString>, default: P) -> Pwhere
StyleProperty: IntoPrimitive<P>,
fn get_or<P>(&self, name: impl Into<ImmutableString>, default: P) -> Pwhere
StyleProperty: IntoPrimitive<P>,
Style::get_or
.Source§fn get_or_default<P>(&self, name: impl Into<ImmutableString>) -> P
fn get_or_default<P>(&self, name: impl Into<ImmutableString>) -> P
Style::get_or_default
.Source§fn property<P>(&self, name: impl Into<ImmutableString>) -> StyledProperty<P>
fn property<P>(&self, name: impl Into<ImmutableString>) -> StyledProperty<P>
Style::property
.Source§impl TextureResourceExtension for Resource<Texture>
impl TextureResourceExtension for Resource<Texture>
Source§fn new_render_target(width: u32, height: u32) -> Resource<Texture> ⓘ
fn new_render_target(width: u32, height: u32) -> Resource<Texture> ⓘ
Source§fn load_from_memory(
kind: ResourceKind,
data: &[u8],
import_options: TextureImportOptions,
) -> Result<Resource<Texture>, TextureError>
fn load_from_memory( kind: ResourceKind, data: &[u8], import_options: TextureImportOptions, ) -> Result<Resource<Texture>, TextureError>
Source§fn from_bytes(
kind: TextureKind,
pixel_kind: TexturePixelKind,
bytes: Vec<u8>,
resource_kind: ResourceKind,
) -> Option<Resource<Texture>>
fn from_bytes( kind: TextureKind, pixel_kind: TexturePixelKind, bytes: Vec<u8>, resource_kind: ResourceKind, ) -> Option<Resource<Texture>>
Source§fn deep_clone(&self) -> Resource<Texture> ⓘ
fn deep_clone(&self) -> Resource<Texture> ⓘ
TextureResource::clone
, this method clones the actual texture data,
which could be slow.Source§impl<T> TypeUuidProvider for Resource<T>where
T: TypedResourceData,
impl<T> TypeUuidProvider for Resource<T>where
T: TypedResourceData,
Source§impl UserInterfaceResourceExtension for Resource<UserInterface>
impl UserInterfaceResourceExtension for Resource<UserInterface>
fn instantiate( &self, ui: &mut UserInterface, ) -> (Handle<UiNode>, NodeHandleMap<UiNode>)
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) -> Result<(), VisitError>
fn visit(&mut self, name: &str, visitor: &mut Visitor) -> Result<(), VisitError>
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>
impl<T> Sync for Resource<T>where
T: Sync,
impl<T> Unpin for Resource<T>where
T: Unpin,
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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
.Source§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
.Source§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.Source§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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Any
. Could be used to downcast a trait object
to a particular type.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Any
. Could be used to downcast a trait object
to a particular type.fn into_any(self: Box<T>) -> Box<dyn Any>
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> FieldValue for Twhere
T: 'static,
impl<T> FieldValue for Twhere
T: 'static,
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<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§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> MessageData for T
impl<T> MessageData for T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.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<T> ScriptMessagePayload for T
impl<T> ScriptMessagePayload for T
Source§fn as_any_ref(&self) -> &(dyn Any + 'static)
fn as_any_ref(&self) -> &(dyn Any + 'static)
self
as &dyn Any
Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
self
as &dyn Any
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.