Skip to main content

NormalizedPath

Struct NormalizedPath 

Source
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

Source

pub fn new(path: impl AsRef<[u8]>) -> Self

Normalize path into an owned virtual resource path.

Source

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.

Source

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.

Source

pub fn as_bstr(&self) -> &BStr

Return this path as a BStr.

Source

pub fn as_bytes(&self) -> &[u8]

Return this path as raw bytes.

Source

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.

Source

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.

Source

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.

Source

pub fn extension(&self) -> Option<&BStr>

Return the extension of the final component, without the dot.

Dotfiles such as .hidden, names ending in ., and paths ending in / have no extension.

Source

pub fn is_empty(&self) -> bool

Return true if the normalized path is empty.

Source

pub fn len(&self) -> usize

Return the normalized path length in bytes.

Trait Implementations§

Source§

impl AsRef<[u8]> for NormalizedPath

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<BStr> for NormalizedPath

Source§

fn as_ref(&self) -> &BStr

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<[u8]> for NormalizedPath

Source§

fn borrow(&self) -> &[u8]

Immutably borrows from an owned value. Read more
Source§

impl Borrow<BStr> for NormalizedPath

Source§

fn borrow(&self) -> &BStr

Immutably borrows from an owned value. Read more
Source§

impl Clone for NormalizedPath

Source§

fn clone(&self) -> NormalizedPath

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NormalizedPath

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NormalizedPath

Source§

fn default() -> NormalizedPath

Returns the “default value” for a type. Read more
Source§

impl From<&[u8]> for NormalizedPath

Source§

fn from(path: &[u8]) -> Self

Converts to this type from the input type.
Source§

impl From<&BStr> for NormalizedPath

Source§

fn from(path: &BStr) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for NormalizedPath

Source§

fn from(path: &str) -> Self

Converts to this type from the input type.
Source§

impl From<BString> for NormalizedPath

Source§

fn from(path: BString) -> Self

Converts to this type from the input type.
Source§

impl From<NormalizedPath> for BString

Source§

fn from(path: NormalizedPath) -> Self

Converts to this type from the input type.
Source§

impl From<NormalizedPath> for Vec<u8>

Source§

fn from(path: NormalizedPath) -> Self

Converts to this type from the input type.
Source§

impl From<String> for NormalizedPath

Source§

fn from(path: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for NormalizedPath

Source§

fn from(path: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl Hash for NormalizedPath

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for NormalizedPath

Source§

fn cmp(&self, other: &NormalizedPath) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for NormalizedPath

Source§

fn eq(&self, other: &NormalizedPath) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for NormalizedPath

Source§

fn partial_cmp(&self, other: &NormalizedPath) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for NormalizedPath

Source§

impl StructuralPartialEq for NormalizedPath

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> MaybeSend for T