-
Notifications
You must be signed in to change notification settings - Fork 771
Expand file tree
/
Copy pathloader.rs
More file actions
33 lines (27 loc) · 705 Bytes
/
loader.rs
File metadata and controls
33 lines (27 loc) · 705 Bytes
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
use super::*;
pub(crate) struct Loader {
paths: Arena<PathBuf>,
srcs: Arena<String>,
}
impl Loader {
pub(crate) fn new() -> Self {
Self {
srcs: Arena::new(),
paths: Arena::new(),
}
}
pub(crate) fn load<'src>(
&'src self,
config: &Config,
root: &Path,
path: &Path,
) -> RunResult<'src, (&'src Path, &'src str)> {
Config::warn_non_unicode_path(config.color, "justfile", path);
let src = fs::read_to_string(path).map_err(|io_error| Error::Load {
path: path.into(),
io_error,
})?;
let relative = path.strip_prefix(root.parent().unwrap()).unwrap_or(path);
Ok((self.paths.alloc(relative.into()), self.srcs.alloc(src)))
}
}