ResourceCache

Trait ResourceCache 

Source
pub trait ResourceCache {
    // Required methods
    fn get_tileset(
        &self,
        path: impl AsRef<ResourcePath>,
    ) -> Option<Arc<Tileset>>;
    fn insert_tileset(
        &mut self,
        path: impl AsRef<ResourcePath>,
        tileset: Arc<Tileset>,
    );
    fn get_template(
        &self,
        path: impl AsRef<ResourcePath>,
    ) -> Option<Arc<Template>>;
    fn insert_template(
        &mut self,
        path: impl AsRef<ResourcePath>,
        tileset: Arc<Template>,
    );
}
Expand description

A trait identifying a data type that holds resources (such as tilesets) and maps them to a ResourcePath to prevent loading them more than once. Normally you don’t need to use this type yourself unless you want to create a custom caching solution to, for instance, integrate with your own.

If you simply want to load a map or tileset, use the Loader type.

Required Methods§

Source

fn get_tileset(&self, path: impl AsRef<ResourcePath>) -> Option<Arc<Tileset>>

Obtains a tileset from the cache, if it exists.

§Example
use std::fs::File;
use tiled::{Tileset, Loader, ResourceCache};

let mut loader = Loader::new();
let path = "assets/tilesheet.tsx";

assert!(loader.cache().get_tileset(path).is_none());
let tileset = Arc::new(loader.load_tsx_tileset(path)?);
loader.cache_mut().insert_tileset(path, tileset);
assert!(loader.cache().get_tileset(path).is_some());
Source

fn insert_tileset( &mut self, path: impl AsRef<ResourcePath>, tileset: Arc<Tileset>, )

Insert a new tileset into the cache.

See Self::get_tileset() for an example.

Source

fn get_template(&self, path: impl AsRef<ResourcePath>) -> Option<Arc<Template>>

Obtains a template from the cache, if it exists.

Source

fn insert_template( &mut self, path: impl AsRef<ResourcePath>, tileset: Arc<Template>, )

Insert a new template into the cache.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§