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.
§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 = PathElementCS::from_bytes(b"hello.txt")?;
assert_eq!(pe.normalized(), "hello.txt");
// Invalid UTF-8 is rejected
assert!(PathElementCS::from_bytes(b"hello\xff.txt").is_err());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.
§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 = 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).