pub type PathElementCS<'a> = PathElementGeneric<'a, CaseSensitive>;Expand description
A validated, normalized, case-sensitive single path element.
Takes a raw path element name, validates it (rejecting empty strings, ., ..,
strings containing / or \0, and unassigned Unicode characters), normalizes it, and computes an OS-compatible
presentation form.
Equality, ordering, and hashing are based on the normalized form.
Case is preserved – "Hello.txt" and "hello.txt" are distinct.
Implements Hash.
Aliased Type§
pub struct PathElementCS<'a> { /* private fields */ }Implementations§
Source§impl<'a> PathElementCS<'a>
impl<'a> PathElementCS<'a>
Sourcepub fn from_bytes(original: impl Into<Cow<'a, [u8]>>) -> Result<Self>
pub fn from_bytes(original: impl Into<Cow<'a, [u8]>>) -> Result<Self>
Creates a new case-sensitive path element from a byte slice.
Invalid UTF-8 is accepted; see Normalization pipeline step 0.
§Errors
Returns Error if the name is invalid (empty, ., ..,
or contains /).
let pe = PathElementCS::from_bytes(b"hello.txt")?;
assert_eq!(pe.normalized(), "hello.txt");
// Invalid UTF-8 is replaced with U+FFFD
let pe = PathElementCS::from_bytes(b"hello\xff.txt")?;
assert_eq!(pe.normalized(), "hello\u{FFFD}.txt");Sourcepub fn from_os_str(original: impl Into<Cow<'a, OsStr>>) -> Result<Self>
Available on crate feature std only.
pub fn from_os_str(original: impl Into<Cow<'a, OsStr>>) -> Result<Self>
std only.Creates a new case-sensitive path element from an OS string.
Invalid UTF-8 is accepted; see Normalization pipeline step 0.
§Errors
Returns Error if the name is invalid (empty, ., ..,
or contains /).
let pe = PathElementCS::from_os_str(OsStr::new("hello.txt"))?;
assert_eq!(pe.normalized(), "hello.txt");Trait Implementations§
Source§impl Hash for PathElementCS<'_>
Hashes by normalized(), consistent with PartialEq. Only
implemented for typed variants, not PathElement.
impl Hash for PathElementCS<'_>
Hashes by normalized(), consistent with PartialEq. Only
implemented for typed variants, not PathElement.
Source§impl<'a> TryFrom<PathElementGeneric<'a, CaseSensitivity>> for PathElementCS<'a>
Attempts to convert a runtime-dynamic PathElement into a PathElementCS.
impl<'a> TryFrom<PathElementGeneric<'a, CaseSensitivity>> for PathElementCS<'a>
Attempts to convert a runtime-dynamic PathElement into a PathElementCS.
Succeeds if the element is case-sensitive. On failure, returns the element
re-wrapped as a PathElementCI in the Err variant (no data is lost).