Struct fyrox::asset::manager::ResourceManager
source · pub struct ResourceManager { /* private fields */ }
Expand description
See module docs.
Implementations§
source§impl ResourceManager
impl ResourceManager
sourcepub fn new(task_pool: Arc<TaskPool>) -> ResourceManager
pub fn new(task_pool: Arc<TaskPool>) -> ResourceManager
Creates a resource manager with default settings and loaders.
sourcepub fn state(&self) -> MutexGuard<'_, RawMutex, ResourceManagerState>
pub fn state(&self) -> MutexGuard<'_, RawMutex, ResourceManagerState>
Returns a guarded reference to internal state of resource manager.
sourcepub fn resource_io(&self) -> Arc<dyn ResourceIo>
pub fn resource_io(&self) -> Arc<dyn ResourceIo>
Returns the ResourceIo used by this resource manager
sourcepub fn request<T>(&self, path: impl AsRef<Path>) -> Resource<T> ⓘwhere
T: TypedResourceData,
pub fn request<T>(&self, path: impl AsRef<Path>) -> Resource<T> ⓘwhere
T: TypedResourceData,
Requests a resource of the given type located at the given path. This method is non-blocking, instead it immediately returns the typed resource wrapper. Loading of the resource is managed automatically in a separate thread (or thread pool) on PC, and JS micro-task (the same thread) on WebAssembly.
§Sharing
If the resource at the given path is already was requested (no matter in which state the actual resource is), this method will return the existing instance. This way the resource manager guarantees that the actual resource data will be loaded once, and it can be shared.
§Waiting
If you need to wait until the resource is loaded, use .await
on the result of the method. Every resource
implements Future
trait and can be used in async
contexts.
§Resource state
Keep in mind, that the resource itself is a small state machine. It could be in three main states:
ResourceState::Pending
- a resource is in the queue to load or still loading.ResourceState::LoadError
- a resource is failed to load.ResourceState::Ok
- a resource is successfully loaded.
Actual resource state can be fetched by Resource::state
method. If you know for sure that the resource
is already loaded, then you can use Resource::data_ref
to obtain a reference to the actual resource data.
Keep in mind, that this method will panic if the resource non in Ok
state.
§Panic
This method will panic, if type UUID of T
does not match the actual type UUID of the resource. If this
is undesirable, use Self::try_request
instead.
sourcepub fn try_request<T>(&self, path: impl AsRef<Path>) -> Option<Resource<T>>where
T: TypedResourceData,
pub fn try_request<T>(&self, path: impl AsRef<Path>) -> Option<Resource<T>>where
T: TypedResourceData,
The same as Self::request
, but returns None
if type UUID of T
does not match the actual type UUID
of the resource.
§Panic
This method does not panic.
sourcepub fn request_untyped<P>(&self, path: P) -> UntypedResource ⓘ
pub fn request_untyped<P>(&self, path: P) -> UntypedResource ⓘ
Same as Self::request
, but returns untyped resource.
sourcepub fn register<P, F>(
&self,
resource: UntypedResource,
path: P,
on_register: F
) -> Result<(), ResourceRegistrationError>
pub fn register<P, F>( &self, resource: UntypedResource, path: P, on_register: F ) -> Result<(), ResourceRegistrationError>
Saves given resources in the specified path and registers it in resource manager, so it will be accessible through it later.
sourcepub async fn move_resource(
&self,
resource: UntypedResource,
new_path: impl AsRef<Path>,
working_directory: impl AsRef<Path>,
filter: impl FnMut(&UntypedResource) -> bool
) -> Result<(), FileLoadError>
pub async fn move_resource( &self, resource: UntypedResource, new_path: impl AsRef<Path>, working_directory: impl AsRef<Path>, filter: impl FnMut(&UntypedResource) -> bool ) -> Result<(), FileLoadError>
Attempts to move a resource from its current location to the new path.
sourcepub async fn reload_resources(&self)
pub async fn reload_resources(&self)
Reloads all loaded resources. Normally it should never be called, because it is very heavy method! This method is asynchronous, it uses all available CPU power to reload resources as fast as possible.
Trait Implementations§
source§impl Clone for ResourceManager
impl Clone for ResourceManager
source§fn clone(&self) -> ResourceManager
fn clone(&self) -> ResourceManager
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for ResourceManager
impl Send for ResourceManager
impl Sync for ResourceManager
impl Unpin for ResourceManager
impl !UnwindSafe for ResourceManager
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.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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
§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.