Struct ResourceManager
pub struct ResourceManager(/* private fields */);Expand description
Use the ResourceManager to access and use resources in kzb files. The resource manager maintains
kzb files and provides mechanisms to load resources from kzb files.
Implementations§
§impl ResourceManager
impl ResourceManager
pub fn add_kzb_file(&self, file_name: impl AsRef<KanziStr>) -> Result<(), Error>
pub fn add_kzb_file(&self, file_name: impl AsRef<KanziStr>) -> Result<(), Error>
Opens a kzb file from the file system and adds it to the list of files. If this function cannot open the file you pass to it or that file is not a kzb file, the function throws an exception.
§Arguments
file_name - The name of the file to open.
pub fn acquire_resource<T>(&self, url: impl AsRef<KanziStr>) -> Result<T, Error>where
T: MetaInherits<Resource>,
pub fn acquire_resource<T>(&self, url: impl AsRef<KanziStr>) -> Result<T, Error>where
T: MetaInherits<Resource>,
Acquires a resource associated with the given URL and casts the resource to the given type. If the resource does not exist or the type cast fails, the function throws an exception.
§Arguments
url- URL of the resource.
§Returns
Shared pointer to the resource.
§Errors
Returns a TYPE_MISMATCH error if the acquired resource cannot be converted to T.
pub fn try_acquire_resource<T>(
&self,
url: impl AsRef<KanziStr>,
) -> Result<Option<T>, Error>where
T: MetaInherits<Resource>,
pub fn try_acquire_resource<T>(
&self,
url: impl AsRef<KanziStr>,
) -> Result<Option<T>, Error>where
T: MetaInherits<Resource>,
pub fn try_acquire_resource_raw( &self, url: impl AsRef<KanziStr>, ) -> Result<Option<Resource>, Error>
pub fn acquire_resources_async(
&self,
urls: &[impl AsRef<KanziStr>],
closure: impl AcquireFinishedCallback,
) -> Result<ResourceAcquireTask, Error>
pub fn acquire_resources_async( &self, urls: &[impl AsRef<KanziStr>], closure: impl AcquireFinishedCallback, ) -> Result<ResourceAcquireTask, Error>
Creates a background task that loads and deploys all resources from a set of URLs. After Kanzi loads and deploys all resources, the function calls the callback you provide.
§Arguments
urls- Set of URLs for resources that you want to load.callback- Callback function that this function calls when Kanzi loads all specified resources.
§Returns
Handle to the async load task. You can pass the handle to #wait to wait for the completion of the load.
pub fn wait(&self, acquire_task: &ResourceAcquireTask) -> Result<(), Error>
pub fn wait(&self, acquire_task: &ResourceAcquireTask) -> Result<(), Error>
Blocks the execution until the async acquire task finishes and calls the callback of the task (unless it has been called already).
§Arguments
acquire_task- Acquire task created by #acquireResourcesAsync.
pub fn unregister_resource(
&self,
url: impl AsRef<KanziStr>,
) -> Result<(), Error>
pub fn unregister_resource( &self, url: impl AsRef<KanziStr>, ) -> Result<(), Error>
Removes the association of the given URL to a resource or a load task. You can use this function to force Kanzi to recreate a resource the next time you use this URL.
§Arguments
url- URL of the resource.
pub fn acquire_loaded_resource<T>(
&self,
url: impl AsRef<KanziStr>,
) -> Result<Option<T>, Error>where
T: MetaInherits<Resource>,
pub fn acquire_loaded_resource<T>(
&self,
url: impl AsRef<KanziStr>,
) -> Result<Option<T>, Error>where
T: MetaInherits<Resource>,
Acquires a resource associated with the given URL. If no resource is associated with the URL, does not try to load the resource.
§Arguments
url- URL of the resource.
§Returns
The resource that was loaded with the given URL. If None is returned, no resource was loaded with the given URL or the type cast failed.
pub fn acquire_loaded_resource_raw(
&self,
url: impl AsRef<KanziStr>,
) -> Result<Option<Resource>, Error>
pub fn acquire_loaded_resource_raw( &self, url: impl AsRef<KanziStr>, ) -> Result<Option<Resource>, Error>
pub fn purge(&self) -> Result<(), Error>
pub fn purge(&self) -> Result<(), Error>
Deletes unreferenced resources. You can use this function to free memory. Destroys all resources that are referenced only by the resource manager.
pub fn register_protocol_handler(
&self,
protocol: impl AsRef<KanziStr>,
loader: impl ResourceProtocol,
) -> Result<(), Error>
pub fn register_protocol_handler( &self, protocol: impl AsRef<KanziStr>, loader: impl ResourceProtocol, ) -> Result<(), Error>
Registers a protocol handler for loading resources specified with the given resource URL protocol (scheme name).
§Arguments
protocol- The protocol name. For example, “http”.handler- The protocol loader function. Kanzi calls this function when you use a URL with the given protocol, and Kanzi does not find an existing resource with that URL. This loader function creates a resource.
pub fn register_protocol_handler_with_reloader(
&self,
protocol: impl AsRef<KanziStr>,
loader: impl ResourceProtocol,
reloader: impl ResourceReloadProtocol,
) -> Result<(), Error>
pub fn register_protocol_handler_with_reloader( &self, protocol: impl AsRef<KanziStr>, loader: impl ResourceProtocol, reloader: impl ResourceReloadProtocol, ) -> Result<(), Error>
Registers a protocol handler for loading resources specified with the given resource URL protocol (scheme name).
§Arguments
protocol- The protocol name. For example, “http”.handler- The protocol loader function. Kanzi calls this function when you use a URL with the given protocol, and Kanzi does not find an existing resource with that URL. This loader function creates a resource.reloader- The protocol reloader function. Kanzi calls this function to recreate an existing resource. Kanzi uses this function only for GPU resources when an application loses GL context in a pause-resume event.
pub fn unregister_protocol_handler(
&self,
protocol: impl AsRef<KanziStr>,
) -> Result<(), Error>
pub fn unregister_protocol_handler( &self, protocol: impl AsRef<KanziStr>, ) -> Result<(), Error>
Unregisters the protocol handler with the given resource URL protocol (scheme name).
pub fn set_default_memory_strategy(
&self,
strategy: MemoryStrategy,
) -> Result<(), Error>
pub fn set_default_memory_strategy( &self, strategy: MemoryStrategy, ) -> Result<(), Error>
pub fn get_default_memory_strategy(&self) -> Result<MemoryStrategy, Error>
pub fn get_default_memory_strategy(&self) -> Result<MemoryStrategy, Error>
pub fn get_resource_usage(&self) -> Result<ResourceUsage, Error>
pub fn get_resource_usage(&self) -> Result<ResourceUsage, Error>
Calculates the memory usage summary for all resources.
Trait Implementations§
§impl Clone for ResourceManager
impl Clone for ResourceManager
§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 more