pub struct PathRef<'a>(/* private fields */);Expand description
A borrowed reference to a path.
This type is to Path as &str is to String. It provides a way to work with path strings without requiring ownership. Uses Cow to avoid allocations when no normalization is needed, but can normalize internal multiple slashes when required.
Implementations§
Source§impl<'a> PathRef<'a>
impl<'a> PathRef<'a>
Sourcepub fn new(s: &'a str) -> Self
pub fn new(s: &'a str) -> Self
Create a new PathRef from a string slice.
Leading and trailing slashes are automatically trimmed. Multiple consecutive internal slashes are collapsed to single slashes.
Sourcepub fn has_prefix<'b>(&self, prefix: impl Into<PathRef<'b>>) -> bool
pub fn has_prefix<'b>(&self, prefix: impl Into<PathRef<'b>>) -> bool
Check if this path has the given prefix, respecting path boundaries.
Unlike String::starts_with, this ensures that “foo” does not match “foobar”. The prefix must either:
- Be exactly equal to this path
- Be followed by a ‘/’ delimiter in the original path
- Be empty (matches everything)
§Examples
use moq_lite::Path;
let path = Path::new("foo/bar");
assert!(path.has_prefix("foo"));
assert!(path.has_prefix(&Path::new("foo")));
assert!(path.has_prefix("foo/"));
assert!(!path.has_prefix("fo"));
let path = Path::new("foobar");
assert!(!path.has_prefix("foo"));Trait Implementations§
impl<'a> Eq for PathRef<'a>
impl<'a> StructuralPartialEq for PathRef<'a>
Auto Trait Implementations§
impl<'a> Freeze for PathRef<'a>
impl<'a> RefUnwindSafe for PathRef<'a>
impl<'a> Send for PathRef<'a>
impl<'a> Sync for PathRef<'a>
impl<'a> Unpin for PathRef<'a>
impl<'a> UnwindSafe for PathRef<'a>
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