summaryrefslogtreecommitdiff
path: root/src/loading/mod.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-05-28 12:44:44 +0200
committerLaurenz <laurmaedje@gmail.com>2021-05-28 12:46:43 +0200
commit0bfee5b7772338fd39bbf708d3e31ea7bcec859b (patch)
tree5f76c7d0529d6c089e8e3383356692dfce09cffb /src/loading/mod.rs
parenteabf28f08187bd9a10bbadbbaf9617e2bc1949aa (diff)
Refactored loading and cache architecture
Diffstat (limited to 'src/loading/mod.rs')
-rw-r--r--src/loading/mod.rs43
1 files changed, 43 insertions, 0 deletions
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<Vec<u8>>;
+
+/// 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<Buffer>;
+
+ /// Load a file from a path.
+ fn load_file(&mut self, path: &str) -> Option<Buffer>;
+}
+
+/// A loader which serves nothing.
+pub struct BlankLoader;
+
+impl Loader for BlankLoader {
+ fn faces(&self) -> &[FaceInfo] {
+ &[]
+ }
+
+ fn load_face(&mut self, _: usize) -> Option<Buffer> {
+ None
+ }
+
+ fn load_file(&mut self, _: &str) -> Option<Buffer> {
+ None
+ }
+}