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§
Sourcefn get_tileset(&self, path: impl AsRef<ResourcePath>) -> Option<Arc<Tileset>>
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());Sourcefn insert_tileset(
&mut self,
path: impl AsRef<ResourcePath>,
tileset: Arc<Tileset>,
)
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.
Sourcefn get_template(&self, path: impl AsRef<ResourcePath>) -> Option<Arc<Template>>
fn get_template(&self, path: impl AsRef<ResourcePath>) -> Option<Arc<Template>>
Obtains a template from the cache, if it exists.
Sourcefn insert_template(
&mut self,
path: impl AsRef<ResourcePath>,
tileset: Arc<Template>,
)
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.