Cache

Struct Cache 

Source
pub struct Cache {}
Expand description

A interface for managing various game resources.

Implementations§

Source§

impl Cache

Source

pub fn load(filename: &str) -> bool

Loads a file into the cache with a blocking operation.

§Arguments
  • filename - The name of the file to load.
§Returns
  • bool - true if the file was loaded successfully, false otherwise.
Source

pub fn load_async(filename: &str, handler: Box<dyn FnMut(bool)>)

Loads a file into the cache asynchronously.

§Arguments
  • filenames - The name of the file(s) to load. This can be a single string or a vector of strings.
  • handler - A callback function that is invoked when the file is loaded.
Source

pub fn update_item(filename: &str, content: &str)

Updates the content of a file loaded in the cache. If the item of filename does not exist in the cache, a new file content will be added into the cache.

§Arguments
  • filename - The name of the file to update.
  • content - The new content for the file.
Source

pub fn update_texture(filename: &str, texture: &Texture2D)

Updates the texture object of the specific filename loaded in the cache. If the texture object of filename does not exist in the cache, it will be added into the cache.

§Arguments
  • filename - The name of the texture to update.
  • texture - The new texture object for the file.
Source

pub fn unload_item_or_type(name: &str) -> bool

Unloads a resource from the cache.

§Arguments
  • name - The type name of resource to unload, could be one of “Texture”, “SVG”, “Clip”, “Frame”, “Model”, “Particle”, “Shader”, “Font”, “Sound”, “Spine”. Or the name of the resource file to unload.
§Returns
  • bool - true if the resource was unloaded successfully, false otherwise.
Source

pub fn unload()

Unloads all resources from the cache.

Source

pub fn remove_unused()

Removes all unused resources (not being referenced) from the cache.

Source

pub fn remove_unused_by_type(type_name: &str)

Removes all unused resources of the given type from the cache.

§Arguments
  • resource_type - The type of resource to remove. This could be one of “Texture”, “SVG”, “Clip”, “Frame”, “Model”, “Particle”, “Shader”, “Font”, “Sound”, “Spine”.

Auto Trait Implementations§

§

impl Freeze for Cache

§

impl RefUnwindSafe for Cache

§

impl Send for Cache

§

impl Sync for Cache

§

impl Unpin for Cache

§

impl UnwindSafe for Cache

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
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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.