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

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>

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 acquire_resource_raw( &self, url: impl AsRef<KanziStr>, ) -> Result<Resource, Error>

Acquires a resource associated with the given URL. If the resource does not exist, the function throws an exception.

§Arguments
  • url - URL of the resource.
§Returns

Shared pointer to the resource.

pub fn try_acquire_resource<T>( &self, url: impl AsRef<KanziStr>, ) -> Result<Option<T>, Error>

Acquires a resource associated with the given URL and casts the resource to the given type. If the type cast fails, the function returns None.

§Arguments
  • url - URL of the resource.
§Returns

If None is returned, resource does not exist or the type cast failed.

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>

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>

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>

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>

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>

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.

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>

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>

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>

Unregisters the protocol handler with the given resource URL protocol (scheme name).

pub fn supports_protocol_handler( &self, protocol: impl AsRef<KanziStr>, ) -> Result<bool, Error>

Checks whether the given resource URL protocol (scheme name) is registered as a protocol handler for the resource manager.

§Arguments
  • protocol - The protocol to check.
§Returns

true if the protocol is registered, otherwise false.

pub fn set_default_memory_strategy( &self, strategy: MemoryStrategy, ) -> Result<(), Error>

Sets the memory release strategy for new resources.

§Arguments
  • strategy - The new memory strategy.

pub fn get_default_memory_strategy(&self) -> Result<MemoryStrategy, Error>

Gets the memory release strategy.

§Returns

The current memory strategy.

pub fn get_resource_usage(&self) -> Result<ResourceUsage, Error>

Calculates the memory usage summary for all resources.

Trait Implementations§

§

impl Clone for ResourceManager

§

fn clone(&self) -> ResourceManager

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AsAny for T
where T: 'static,

§

fn as_any(&self) -> &(dyn Any + 'static)

§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Inherits<T> for T

§

fn upcast(self) -> Base

§

fn upcast_ref(&self) -> &Base

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.