From 0bfee5b7772338fd39bbf708d3e31ea7bcec859b Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 28 May 2021 12:44:44 +0200 Subject: Refactored loading and cache architecture --- src/loading/mod.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/loading/mod.rs (limited to 'src/loading/mod.rs') diff --git a/src/loading/mod.rs b/src/loading/mod.rs new file mode 100644 index 00000000..818e7e3c --- /dev/null +++ b/src/loading/mod.rs @@ -0,0 +1,43 @@ +//! Resource loading. + +#[cfg(feature = "fs")] +mod fs; + +#[cfg(feature = "fs")] +pub use fs::*; + +use std::rc::Rc; + +use crate::font::FaceInfo; + +/// A shared byte buffer. +pub type Buffer = Rc>; + +/// Loads resources from a local or remote source. +pub trait Loader { + /// Descriptions of all font faces this loader serves. + fn faces(&self) -> &[FaceInfo]; + + /// Load the font face with the given index in [`faces()`](Self::faces). + fn load_face(&mut self, idx: usize) -> Option; + + /// Load a file from a path. + fn load_file(&mut self, path: &str) -> Option; +} + +/// A loader which serves nothing. +pub struct BlankLoader; + +impl Loader for BlankLoader { + fn faces(&self) -> &[FaceInfo] { + &[] + } + + fn load_face(&mut self, _: usize) -> Option { + None + } + + fn load_file(&mut self, _: &str) -> Option { + None + } +} -- cgit v1.2.3