pub struct NormalizedPath(/* private fields */);Expand description
A byte-first normalized virtual resource path.
NormalizedPath::new and the input From impls apply normalize_path.
The normalized-byte adoption constructors require the caller to provide bytes
that are already normalized. This type is intended for repeated lookups where
normalizing the query every time would allocate and burn cycles for no useful
reason.
Implementations§
Source§impl NormalizedPath
impl NormalizedPath
Sourcepub fn try_from_normalized_bytes(path: Vec<u8>) -> Result<Self, Vec<u8>>
pub fn try_from_normalized_bytes(path: Vec<u8>) -> Result<Self, Vec<u8>>
Build from bytes that are already normalized.
Returns the original bytes on rejection so callers can log, repair, or normalize them without cloning first. Use this when avoiding a second normalization pass matters and the caller can handle rejection.
§Errors
Returns the original path when it does not satisfy
is_normalized_path.
Sourcepub fn from_normalized_bytes_unchecked(path: Vec<u8>) -> Self
pub fn from_normalized_bytes_unchecked(path: Vec<u8>) -> Self
Build from bytes that are already normalized without checking them.
path should satisfy is_normalized_path. Passing non-normalized bytes
breaks the logical invariant that every NormalizedPath contains
normalized virtual path spelling. That can produce cache misses and
duplicate keys. It is not memory-unsafe; it is just wrong, which is quite
bad enough.
Sourcepub fn to_str(&self) -> Result<&str, Utf8Error>
pub fn to_str(&self) -> Result<&str, Utf8Error>
Return this path as UTF-8 when the normalized bytes are valid UTF-8.
This is a convenience for string-oriented callers. It is not a promise that virtual resource paths are Unicode, display-safe, C-string-safe, or host filesystem paths. Valid UTF-8 paths may still contain NUL bytes.
§Errors
Returns Utf8Error if the path contains invalid UTF-8 bytes.
Sourcepub fn file_name(&self) -> Option<&BStr>
pub fn file_name(&self) -> Option<&BStr>
Return the final non-empty component of this virtual path.
A trailing separator is ignored for component extraction, so foo/bar/
has file name bar.
Sourcepub fn parent(&self) -> Option<&BStr>
pub fn parent(&self) -> Option<&BStr>
Return the parent portion of this virtual path.
This is a byte-level virtual path operation. It does not interpret .,
.., drive prefixes, roots, or host filesystem rules.
Trait Implementations§
Source§impl AsRef<[u8]> for NormalizedPath
impl AsRef<[u8]> for NormalizedPath
Source§impl AsRef<BStr> for NormalizedPath
impl AsRef<BStr> for NormalizedPath
Source§impl Borrow<[u8]> for NormalizedPath
impl Borrow<[u8]> for NormalizedPath
Source§impl Borrow<BStr> for NormalizedPath
impl Borrow<BStr> for NormalizedPath
Source§impl Clone for NormalizedPath
impl Clone for NormalizedPath
Source§fn clone(&self) -> NormalizedPath
fn clone(&self) -> NormalizedPath
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NormalizedPath
impl Debug for NormalizedPath
Source§impl Default for NormalizedPath
impl Default for NormalizedPath
Source§fn default() -> NormalizedPath
fn default() -> NormalizedPath
Source§impl From<&[u8]> for NormalizedPath
impl From<&[u8]> for NormalizedPath
Source§impl From<&BStr> for NormalizedPath
impl From<&BStr> for NormalizedPath
Source§impl From<&str> for NormalizedPath
impl From<&str> for NormalizedPath
Source§impl From<BString> for NormalizedPath
impl From<BString> for NormalizedPath
Source§impl From<NormalizedPath> for BString
impl From<NormalizedPath> for BString
Source§fn from(path: NormalizedPath) -> Self
fn from(path: NormalizedPath) -> Self
Source§impl From<NormalizedPath> for Vec<u8>
impl From<NormalizedPath> for Vec<u8>
Source§fn from(path: NormalizedPath) -> Self
fn from(path: NormalizedPath) -> Self
Source§impl From<String> for NormalizedPath
impl From<String> for NormalizedPath
Source§impl Hash for NormalizedPath
impl Hash for NormalizedPath
Source§impl Ord for NormalizedPath
impl Ord for NormalizedPath
Source§fn cmp(&self, other: &NormalizedPath) -> Ordering
fn cmp(&self, other: &NormalizedPath) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for NormalizedPath
impl PartialEq for NormalizedPath
Source§impl PartialOrd for NormalizedPath
impl PartialOrd for NormalizedPath
impl Eq for NormalizedPath
impl StructuralPartialEq for NormalizedPath
Auto Trait Implementations§
impl Freeze for NormalizedPath
impl RefUnwindSafe for NormalizedPath
impl Send for NormalizedPath
impl Sync for NormalizedPath
impl Unpin for NormalizedPath
impl UnsafeUnpin for NormalizedPath
impl UnwindSafe for NormalizedPath
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more