summaryrefslogtreecommitdiff
path: root/src/cache.rs
blob: 2aa276aa40062ee7c79a63770fc0d0a120da5a7b (plain) (blame)
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
//! Caching of compilation artifacts.

use crate::font::FontCache;
use crate::image::ImageCache;
#[cfg(feature = "layout-cache")]
use crate::layout::LayoutCache;
use crate::loading::Loader;

/// Caches compilation artifacts.
pub struct Cache {
    /// Caches parsed font faces.
    pub font: FontCache,
    /// Caches decoded images.
    pub image: ImageCache,
    /// Caches layouting artifacts.
    #[cfg(feature = "layout-cache")]
    pub layout: LayoutCache,
}

impl Cache {
    /// Create a new, empty cache.
    pub fn new(loader: &dyn Loader) -> Self {
        Self {
            font: FontCache::new(loader),
            image: ImageCache::new(),
            #[cfg(feature = "layout-cache")]
            layout: LayoutCache::new(),
        }
    }
}