struct NormalizedPath(BString)An owned, normalized virtual resource path, for storing and looking up. Every way of making one from arbitrary input normalizes it; the two ways of adopting bytes as they are require them to be normalized already.
Clone, Debug, Default (the empty path), Eq, Hash, Ord and PartialOrd, all over the
normalized bytes. Ordering is byte order.
Making one#
fn new(path: impl AsRef<[u8]>) -> NormalizedPathNormalizes path.
impl From<&[u8] | &str | &BStr | Vec<u8> | String | BString> for NormalizedPathEach normalizes, like new.
fn try_from_normalized_bytes(path: Vec<u8>) -> Result<NormalizedPath, Vec<u8>>Adopts path without copying if it is normalized, and hands it back unchanged as the error if it
is not.
fn from_normalized_bytes_unchecked(path: Vec<u8>) -> NormalizedPathAdopts path without checking; debug builds assert it. Bytes that are not normalized break
nothing in memory, only lookups: the key will not match its normalized spelling.
Reading it#
fn as_bytes(&self) -> &[u8]fn as_bstr(&self) -> &BStrfn to_str(&self) -> Result<&str, Utf8Error>The key as &str when its bytes are valid UTF-8. Valid UTF-8 can still hold NUL and control
bytes; it is not a C string or a display string.
fn len(&self) -> usizefn is_empty(&self) -> boolLength in bytes, and whether it is the empty path.
Inspecting#
fn parent(&self) -> Option<&BStr>fn file_name(&self) -> Option<&BStr>fn extension(&self) -> Option<&BStr>The same as parent_normalized, file_name_normalized and extension_normalized
on the key’s bytes.
Borrowing and converting#
| Implementation | Use |
|---|---|
Borrow<[u8]>, Borrow<BStr> | Look a key up in a HashMap or BTreeMap by normalized bytes, without building a key |
AsRef<[u8]>, AsRef<BStr> | Pass a key wherever bytes are accepted |
From<NormalizedPath> for Vec<u8>, for BString | Move the bytes out without copying |