summaryrefslogtreecommitdiff
path: root/src/loading/mod.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-05-29 15:45:57 +0200
committerLaurenz <laurmaedje@gmail.com>2021-05-31 22:33:40 +0200
commite023bf2ac9f5796355d9485afc16781196bf212b (patch)
tree26d4487de0c4e2d0f69182483301de867cb5fa34 /src/loading/mod.rs
parent9f77f09aacd1fb0fd6138a6d16ed2755f6bfae3f (diff)
Module loading system
Detects cyclic imports and loads each module only once per compilation.
Diffstat (limited to 'src/loading/mod.rs')
-rw-r--r--src/loading/mod.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/loading/mod.rs b/src/loading/mod.rs
index 818e7e3c..b4e5d160 100644
--- a/src/loading/mod.rs
+++ b/src/loading/mod.rs
@@ -6,6 +6,7 @@ mod fs;
#[cfg(feature = "fs")]
pub use fs::*;
+use std::path::Path;
use std::rc::Rc;
use crate::font::FaceInfo;
@@ -18,13 +19,22 @@ pub trait Loader {
/// Descriptions of all font faces this loader serves.
fn faces(&self) -> &[FaceInfo];
+ /// Resolve a hash that is the same for all paths pointing to the same file.
+ ///
+ /// Should return `None` if the file does not exist.
+ fn resolve(&self, path: &Path) -> Option<FileHash>;
+
/// 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>;
+ fn load_file(&mut self, path: &Path) -> Option<Buffer>;
}
+/// A hash that must be the same for all paths pointing to the same file.
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
+pub struct FileHash(pub u64);
+
/// A loader which serves nothing.
pub struct BlankLoader;
@@ -33,11 +43,15 @@ impl Loader for BlankLoader {
&[]
}
+ fn resolve(&self, _: &Path) -> Option<FileHash> {
+ None
+ }
+
fn load_face(&mut self, _: usize) -> Option<Buffer> {
None
}
- fn load_file(&mut self, _: &str) -> Option<Buffer> {
+ fn load_file(&mut self, _: &Path) -> Option<Buffer> {
None
}
}