pub struct PathComponent(/* private fields */);Expand description
A single validated path component.
Guarantees: the inner string is a valid StructFS path component (UAX#31
identifier or pure numeric). Cannot be constructed from an arbitrary
string without validation, which is what lets the path! macro accept
PathComponent expressions without a runtime check.
§Arbitrary strings
Real-world identifiers (my-account, hello world, UUIDs with dashes)
are often not valid components. Use PathComponent::encode to embed
them losslessly via Namecode and
PathComponent::decode to recover the original string.
Implementations§
Source§impl PathComponent
impl PathComponent
Sourcepub fn try_new(s: impl Into<String>) -> Result<Self, PathError>
pub fn try_new(s: impl Into<String>) -> Result<Self, PathError>
Validate and wrap a string as a path component.
Sourcepub fn encode(s: &str) -> Self
pub fn encode(s: &str) -> Self
Encode an arbitrary string as a valid path component.
Valid UAX#31 identifiers pass through unchanged; everything else
(punctuation, spaces, leading digits) is Namecode-encoded into a
_N_-prefixed identifier. Always succeeds and is deterministic.
Reverse with PathComponent::decode.
Sourcepub fn decode(&self) -> Result<String, PathError>
pub fn decode(&self) -> Result<String, PathError>
Decode a component produced by PathComponent::encode back to the
original string.
Components that are not Namecode-encoded are returned unchanged
(matching encode’s pass-through of valid identifiers). Returns an
error only for a malformed _N_-prefixed component.
Sourcepub fn validated_str(&self) -> &str
pub fn validated_str(&self) -> &str
Borrow the validated string.
Used by the path! macro to enforce that only PathComponent values
(not bare String/&str) are accepted as runtime path components.
Named distinctly so no standard type matches.
Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Consume and return the inner string.
Trait Implementations§
Source§impl AsRef<str> for PathComponent
impl AsRef<str> for PathComponent
Source§impl Clone for PathComponent
impl Clone for PathComponent
Source§fn clone(&self) -> PathComponent
fn clone(&self) -> PathComponent
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more