Skip to main content

PathElementCI

Type Alias PathElementCI 

Source
pub type PathElementCI<'a> = PathElementGeneric<'a, CaseInsensitive>;
Expand description

A validated, normalized, case-insensitive single path element.

Takes a raw path element name, validates it (rejecting empty strings, ., .., strings containing / or \0, and unassigned Unicode characters), normalizes it case-insensitively, and computes an OS-compatible presentation form.

Equality, ordering, and hashing are based on the normalized (case-folded) form. "Hello.txt" and "hello.txt" are equal. Implements Hash.

Aliased Type§

pub struct PathElementCI<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> PathElementCI<'a>

Source

pub fn new(original: impl Into<Cow<'a, str>>) -> Result<Self>

Creates a new case-insensitive path element from a string.

§Errors

Returns Error if the name is invalid (empty, ., .., contains /, \0, or unassigned Unicode characters).

let pe = PathElementCI::new("Hello.txt")?;
assert_eq!(pe.normalized(), "hello.txt"); // case-folded
Source

pub fn from_bytes(original: impl Into<Cow<'a, [u8]>>) -> Result<Self>

Creates a new case-insensitive path element from a byte slice.

§Errors

Returns Error if the input is not valid UTF-8 or the name is invalid (empty, ., .., contains /, \0, or unassigned Unicode characters).

let pe = PathElementCI::from_bytes(b"Hello.TXT")?;
assert_eq!(pe.normalized(), "hello.txt");
Source

pub fn from_os_str(original: impl Into<Cow<'a, OsStr>>) -> Result<Self>

Available on crate feature std only.

Creates a new case-insensitive path element from an OS string.

§Errors

Returns Error if the input is not valid UTF-8 or the name is invalid (empty, ., .., contains /, \0, or unassigned Unicode characters).

Trait Implementations§

Source§

impl Hash for PathElementCI<'_>

Hashes by normalized(), consistent with PartialEq. Only implemented for typed variants, not PathElement.

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<'a> TryFrom<PathElementGeneric<'a, CaseSensitivity>> for PathElementCI<'a>

Attempts to convert a runtime-dynamic PathElement into a PathElementCI.

Succeeds if the element is case-insensitive. On failure, returns the element re-wrapped as a PathElementCS in the Err variant (no data is lost).

Source§

type Error = PathElementGeneric<'a, CaseSensitive>

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

fn try_from(pe: PathElement<'a>) -> Result<Self, Self::Error>

Performs the conversion.