pub struct SourcePath(/* private fields */);Expand description
A normalised, relative, /-separated path to a source file, used as the
primary key for files everywhere in sealmap.
Normalisation makes keys identical on every platform:
use sealmap_model::SourcePath;
let a = SourcePath::new("src/./net/../lib.rs").unwrap();
let b = SourcePath::new("src\\lib.rs").unwrap();
assert_eq!(a, b);
assert_eq!(a.as_str(), "src/lib.rs");
assert!(SourcePath::new("/etc/passwd").is_err());
assert!(SourcePath::new("../outside.rs").is_err());Implementations§
Source§impl SourcePath
impl SourcePath
Sourcepub fn new(raw: impl AsRef<str>) -> Result<Self, PathError>
pub fn new(raw: impl AsRef<str>) -> Result<Self, PathError>
Normalise raw into a SourcePath.
Backslashes are treated as separators, . components are dropped and
.. components are resolved lexically. Absolute paths and paths that
escape the root are rejected.
Sourcepub fn relative_to(path: &Path, root: &Path) -> Result<Self, PathError>
pub fn relative_to(path: &Path, root: &Path) -> Result<Self, PathError>
Make path relative to root and normalise it.
Non-UTF-8 components are converted lossily.
Sourcepub fn components(&self) -> impl Iterator<Item = &str>
pub fn components(&self) -> impl Iterator<Item = &str>
Path components in order.
Sourcepub fn with_suffix(&self, suffix: &str) -> Self
pub fn with_suffix(&self, suffix: &str) -> Self
Append a suffix to the whole path (src/lib.rs + .mmd →
src/lib.rs.mmd). This is how the corpus maps sources 1:1 to diagrams.
Trait Implementations§
Source§impl Clone for SourcePath
impl Clone for SourcePath
Source§impl Debug for SourcePath
impl Debug for SourcePath
Source§impl<'de> Deserialize<'de> for SourcePath
impl<'de> Deserialize<'de> for SourcePath
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for SourcePath
impl Display for SourcePath
impl Eq for SourcePath
Source§impl From<SourcePath> for String
impl From<SourcePath> for String
Source§fn from(value: SourcePath) -> Self
fn from(value: SourcePath) -> Self
Converts to this type from the input type.
Source§impl Hash for SourcePath
impl Hash for SourcePath
Source§impl Ord for SourcePath
impl Ord for SourcePath
1.21.0 (const: unstable) · 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
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialEq for SourcePath
impl PartialEq for SourcePath
Source§impl PartialOrd for SourcePath
impl PartialOrd for SourcePath
Source§impl Serialize for SourcePath
impl Serialize for SourcePath
impl StructuralPartialEq for SourcePath
Auto Trait Implementations§
impl Freeze for SourcePath
impl RefUnwindSafe for SourcePath
impl Send for SourcePath
impl Sync for SourcePath
impl Unpin for SourcePath
impl UnsafeUnpin for SourcePath
impl UnwindSafe for SourcePath
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