Skip to main content

TileCache

Trait TileCache 

Source
pub trait TileCache: Send + Sync {
    // Required methods
    fn get(&self, key: TileKey) -> Option<Image>;
    fn put(&self, key: TileKey, bytes: &[u8]) -> Result<(), CacheError>;

    // Provided methods
    fn contains(&self, key: TileKey) -> bool { ... }
    fn get_bytes(&self, _key: TileKey) -> Option<Vec<u8>> { ... }
}
Expand description

Local storage for downloaded tiles. Implementations decide whether the backing is a slippy-map directory tree, an MBTiles SQLite db, a single PMTiles archive, or an in-memory HashMap for tests.

Required Methods§

Source

fn get(&self, key: TileKey) -> Option<Image>

Look up the cached tile, decoded as a slint::Image. Returns None if the tile isn’t cached (or if its bytes failed to decode). Implementations should be cheap on the miss path.

Source

fn put(&self, key: TileKey, bytes: &[u8]) -> Result<(), CacheError>

Store raw bytes (typically a PNG payload exactly as the source served it — the cache is encoding-agnostic). Errors here are returned but a fetching source will typically just log and keep going.

Provided Methods§

Source

fn contains(&self, key: TileKey) -> bool

Quick existence check that avoids the decode cost of get. Default implementation falls back to get(key).is_some() — override on backends where existence is cheaper to test.

Source

fn get_bytes(&self, _key: TileKey) -> Option<Vec<u8>>

Read the raw bytes for a tile, if cached. Used by sources that want to do their own (off-UI-thread) decoding rather than the in-thread decode that get performs. Default returns None — backends that store raw bytes (FileTileCache) should override.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§