pub struct ProjectPath(String);Expand description
A canonical, project-relative resource path used as a file dependency’s identity.
The stored string is the identity, in canonical form:
- backslashes folded to
/(soa\banda/bagree across platforms), .and empty segments dropped,..resolved lexically,- each segment NFC-normalized.
So ./a.mos, a.mos, and dir\..\dir/a.mos all yield the same
ProjectPath, which is exactly what makes a file DependencyId
deterministic for the same logical input (design note §3.1).
Normalization is lexical only: it never touches the filesystem, so it
cannot turn a relative path absolute or leak machine layout into the
identity. Absolute filesystem paths are valid inputs at outer boundaries,
but they must be made project-relative before becoming a ProjectPath.
§Examples
use mos_cache::ProjectPath;
assert_eq!(
ProjectPath::new("./ch/../ch/intro.mos").map(|path| path.as_str().to_owned()),
Ok("ch/intro.mos".to_owned())
);
assert_eq!(
ProjectPath::new(r"figures\logo.png").map(|path| path.as_str().to_owned()),
Ok("figures/logo.png".to_owned())
);Tuple Fields§
§0: StringImplementations§
Source§impl ProjectPath
impl ProjectPath
Sourcepub fn new(path: impl AsRef<str>) -> Result<Self, ProjectPathError>
pub fn new(path: impl AsRef<str>) -> Result<Self, ProjectPathError>
Canonicalize a project-relative path into a ProjectPath. Absolute
paths must be relativized against the project root before calling this.
§Errors
Returns ProjectPathError when path is empty, absolute, or escapes
above the project root with ...
§Examples
use mos_cache::ProjectPath;
// Decomposed "é" (e + combining acute) folds to the composed form.
assert_eq!(ProjectPath::new("e\u{0301}.bib"), ProjectPath::new("\u{00e9}.bib"));Trait Implementations§
Source§impl Clone for ProjectPath
impl Clone for ProjectPath
Source§fn clone(&self) -> ProjectPath
fn clone(&self) -> ProjectPath
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more