blob: 4841e7522bb699d61e7ed93609d6f7175e6b2dbd (
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
//! Resource loading.
#[cfg(feature = "fs")]
mod fs;
mod mem;
#[cfg(feature = "fs")]
pub use fs::*;
pub use mem::*;
use std::io;
use std::path::Path;
use crate::font::FaceInfo;
/// A hash that identifies a file.
///
/// Such a hash can be [resolved](Loader::resolve) from a path.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct FileHash(pub u64);
/// Loads resources from a local or remote source.
pub trait Loader {
/// Descriptions of all font faces this loader serves.
fn faces(&self) -> &[FaceInfo];
/// Resolve a hash that is the same for this and all other paths pointing to
/// the same file.
fn resolve(&self, path: &Path) -> io::Result<FileHash>;
/// Load a file from a path.
fn load(&self, path: &Path) -> io::Result<Vec<u8>>;
}
/// A loader which serves nothing.
pub struct BlankLoader;
impl Loader for BlankLoader {
fn faces(&self) -> &[FaceInfo] {
&[]
}
fn resolve(&self, _: &Path) -> io::Result<FileHash> {
Err(io::ErrorKind::NotFound.into())
}
fn load(&self, _: &Path) -> io::Result<Vec<u8>> {
Err(io::ErrorKind::NotFound.into())
}
}
|