Skip to main content

Path

Struct Path 

Source
pub struct Path(/* private fields */);
Expand description

A validated path in StructFS.

Path components must be valid Unicode identifiers (per UAX#31) or numeric strings (for array indexing). This ensures paths can be used as identifiers in most programming languages.

§Refinement of LLPath

Path is a validated refinement of the low-level LLPath: it wraps an LLPath whose every component is additionally guaranteed to be valid UTF-8 and a valid component grammar (identifier or numeric). Because a Path is an LLPath that has been validated, widening (as_ll / into_ll) is free, and narrowing (validate) is the single place validation happens. Components are stored as byte components, so Path -> LLPath never copies and structural ops (join/slice/strip_prefix) clone Bytes (reference-count bumps) rather than deep-copying Strings.

Implementations§

Source§

impl Path

Source

pub fn parse(s: &str) -> Result<Path, PathError>

Parse a path string, validating components.

§Path Syntax
  • Components are separated by /
  • Empty components are ignored (normalizes // and trailing /)
  • Each component must be a valid identifier or numeric string
§Examples
use structfs_core_store::Path;

let path = Path::parse("users/123/name").unwrap();
assert_eq!(path.len(), 3);

// Trailing slashes are normalized
assert_eq!(Path::parse("foo/bar/").unwrap(), Path::parse("foo/bar").unwrap());
Source

pub fn from_components(components: Vec<String>) -> Path

Create a path from pre-validated components.

§Panics

Panics if any component is invalid. Use try_from_components for fallible construction.

Source

pub fn try_from_components(components: Vec<String>) -> Result<Path, PathError>

Try to create a path from components, validating each.

Source

pub fn validate_component( component: &str, position: usize, ) -> Result<(), PathError>

Validate a single path component against the StructFS grammar.

The grammar is shared with the compile-time path! macro via the structfs-path-validation crate: a component is a UAX#31 identifier (an underscore prefix is allowed when followed by more identifier characters) or a pure numeric string.

position is only used to build the error; pass 0 when validating a component in isolation.

Source

pub fn is_empty(&self) -> bool

Check if this path is empty (root path).

Source

pub fn len(&self) -> usize

Get the number of components.

Source

pub fn iter(&self) -> impl Iterator<Item = &str>

Iterate over components as validated &strs.

Source

pub fn join(&self, other: &Path) -> Path

Join this path with another.

Source

pub fn child(&self, component: impl Into<PathComponent>) -> Path

Return a new path with the component appended.

Source

pub fn push(&mut self, component: impl Into<PathComponent>)

Append a component in place.

Source

pub fn has_prefix(&self, prefix: &Path) -> bool

Check if this path has the given prefix.

Source

pub fn strip_prefix(&self, prefix: &Path) -> Option<Path>

Strip a prefix from this path.

Returns None if the prefix doesn’t match.

Source

pub fn slice(&self, start: usize, end: usize) -> Path

Get a slice of components as a new path.

Source

pub fn as_ll(&self) -> &LLPath

Borrow this path as its underlying LLPath — the free widening from the validated high-level contract to the opaque low-level one.

Source

pub fn into_ll(self) -> LLPath

Consume this path into its underlying LLPath — free widening with no component copy.

Source

pub fn validate(ll: LLPath) -> Result<Path, PathError>

Validate an LLPath into a Path — the single narrowing point where opaque bytes become a validated identifier path. Reuses the Bytes components (no copy); fails if any component is not valid UTF-8 or not a valid component grammar.

Source

pub fn from_ll_unchecked(ll: LLPath) -> Path

Wrap an LLPath known to already satisfy the Path invariant, without re-validating. This is the byte-path analogue of from_validated_components: use it for paths that originated host-side from a Path (e.g. a write result path echoed back), so internal LL->HL hops don’t re-pay validation. Debug builds re-check as a safety net.

Source

pub fn to_ll_path(&self) -> LLPath

Convert to an owned LL path (byte components).

Now a cheap clone (each component is a reference-counted Bytes); prefer as_ll/into_ll to avoid even that.

Source

pub fn try_from_ll_path(ll_path: &[impl AsRef<[u8]>]) -> Result<Path, PathError>

Try to create from borrowed LL path components (byte slices).

Copies the components into owned Bytes and validates. Fails if any component is not valid UTF-8 or not a valid identifier. For an owned LLPath, prefer validate to reuse its Bytes.

Trait Implementations§

Source§

impl Clone for Path

Source§

fn clone(&self) -> Path

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Path

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Path

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Path, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Path

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for Path

Source§

impl From<PathComponent> for Path

Source§

fn from(c: PathComponent) -> Path

Converts to this type from the input type.
Source§

impl FromIterator<PathComponent> for Path

Source§

fn from_iter<I>(iter: I) -> Path
where I: IntoIterator<Item = PathComponent>,

Creates a value from an iterator. Read more
Source§

impl Hash for Path

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

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 Index<usize> for Path

Source§

type Output = str

The returned type after indexing.
Source§

fn index(&self, i: usize) -> &<Path as Index<usize>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Ord for Path

Source§

fn cmp(&self, other: &Path) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Path

Source§

fn eq(&self, other: &Path) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Path

Source§

fn partial_cmp(&self, other: &Path) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Path

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Path

Auto Trait Implementations§

§

impl Freeze for Path

§

impl RefUnwindSafe for Path

§

impl Send for Path

§

impl Sync for Path

§

impl Unpin for Path

§

impl UnsafeUnpin for Path

§

impl UnwindSafe for Path

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.