ferrite_cache/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::path::PathBuf;
use thiserror::Error;

mod manager;
mod types;

pub use manager::CacheManager;
pub use types::{CacheConfig, CacheHandle};
#[derive(Error, Debug)]
pub enum CacheError {
    #[error("Failed to load image from {path}: {source}")]
    ImageLoad { path: PathBuf, source: ImageLoadError },

    #[error("Cache capacity reached ({current} images, maximum {maximum})")]
    CapacityExceeded { current: usize, maximum: usize },

    #[error("File system error: {0}")]
    FileSystem(#[from] std::io::Error),

    #[error("Configuration error: {0}")]
    Config(String),
}

#[derive(Error, Debug)]
pub enum ImageLoadError {
    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),

    #[error("Invalid image format: {0}")]
    Format(String),
}

pub type CacheResult<T> = Result<T, CacheError>;
pub type LoadResult<T> = Result<T, ImageLoadError>;