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.
§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
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ProjectPath
impl Debug for ProjectPath
Source§impl Display for ProjectPath
impl Display for ProjectPath
Source§impl Hash for ProjectPath
impl Hash for ProjectPath
Source§impl Ord for ProjectPath
impl Ord for ProjectPath
Source§fn cmp(&self, other: &ProjectPath) -> Ordering
fn cmp(&self, other: &ProjectPath) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for ProjectPath
impl PartialEq for ProjectPath
Source§impl PartialOrd for ProjectPath
impl PartialOrd for ProjectPath
impl Eq for ProjectPath
impl StructuralPartialEq for ProjectPath
Auto Trait Implementations§
impl Freeze for ProjectPath
impl RefUnwindSafe for ProjectPath
impl Send for ProjectPath
impl Sync for ProjectPath
impl Unpin for ProjectPath
impl UnsafeUnpin for ProjectPath
impl UnwindSafe for ProjectPath
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more