Struct Path

Source
pub struct Path<const MCL: usize, const MCC: usize, const MPL: usize> { /* private fields */ }
Expand description

An immutable Willow path. Thread-safe, cheap to clone, cheap to take prefixes of, expensive to append to.

Enforces that each component has a length of at most MCL (max_component_length), that each path has at most MCC (max_component_ccount) components, and that the total size in bytes of all components is at most MPL (max_path_length).

Implementations§

Source§

impl<const MCL: usize, const MCC: usize, const MPL: usize> Path<MCL, MCC, MPL>

Source

pub fn new_empty() -> Self

Construct an empty path, i.e., a path of zero components.

§Complexity

Runs in O(1), performs no allocations.

Source

pub fn new_singleton(comp: Component<'_, MCL>) -> Result<Self, InvalidPathError>

Construct a singleton path, i.e., a path of exactly one component.

Copies the bytes of the component into an owned allocation on the heap.

§Complexity

Runs in O(n), where n is the length of the component. Performs a single allocation of O(n) bytes.

Source

pub fn new_from_iter<'a, I>( total_length: usize, iter: &mut I, ) -> Result<Self, InvalidPathError>
where I: ExactSizeIterator<Item = Component<'a, MCL>>,

Construct a path of known total length from an ExactSizeIterator of components.

Copies the bytes of the components into an owned allocation on the heap.

Panics if the claimed total_length does not match the sum of the lengths of all the components.

§Complexity

Runs in O(n), where n is the total length of the path in bytes. Performs a single allocation of O(n) bytes.

Source

pub fn new_from_slice( components: &[Component<'_, MCL>], ) -> Result<Self, InvalidPathError>

Construct a path from a slice of components.

Copies the bytes of the components into an owned allocation on the heap.

§Complexity

Runs in O(n), where n is the total length of the path in bytes. Performs a single allocation of O(n) bytes.

Source

pub fn append(&self, comp: Component<'_, MCL>) -> Result<Self, InvalidPathError>

Construct a new path by appending a component to this one.

Creates a fully separate copy of the new data on the heap; this function is not more efficient than constructing the new path from scratch.

§Complexity

Runs in O(n), where n is the total length of the new path in bytes. Performs a single allocation of O(n) bytes.

Source

pub fn append_slice( &self, components: &[Component<'_, MCL>], ) -> Result<Self, InvalidPathError>

Construct a new path by appending a slice of components to this one.

Creates a fully separate copy of the new data on the heap; this function is not more efficient than constructing the new path from scratch.

§Complexity

Runs in O(n), where n is the total length of the new path in bytes. Performs a single allocation of O(n) bytes.

Source

pub fn get_component_count(&self) -> usize

Get the number of components in this path.

Guaranteed to be at most MCC.

§Complexity

Runs in O(1), performs no allocations.

Source

pub fn is_empty(&self) -> bool

Return whether this path has zero components.

§Complexity

Runs in O(1), performs no allocations.

Source

pub fn get_path_length(&self) -> usize

Get the sum of the lengths of all components in this path.

Guaranteed to be at most MCC.

§Complexity

Runs in O(1), performs no allocations.

Source

pub fn get_component(&self, i: usize) -> Option<Component<'_, MCL>>

Get the i-th Component of this path.

§Complexity

Runs in O(1), performs no allocations.

Source

pub fn get_owned_component(&self, i: usize) -> Option<OwnedComponent<MCL>>

Get an owned handle to the i-th Component of this path.

§Complexity

Runs in O(1), performs no allocations.

Source

pub fn components( &self, ) -> impl DoubleEndedIterator<Item = Component<'_, MCL>> + ExactSizeIterator<Item = Component<'_, MCL>>

Create an iterator over the components of this path.

Stepping the iterator takes O(1) time and performs no memory allocations.

§Complexity

Runs in O(1), performs no allocations.

Source

pub fn suffix_components( &self, i: usize, ) -> impl DoubleEndedIterator<Item = Component<'_, MCL>> + ExactSizeIterator<Item = Component<'_, MCL>>

Create an iterator over the components of this path, starting at the i-th component. If i is greater than or equal to the number of components, the iterator yields zero items.

Stepping the iterator takes O(1) time and performs no memory allocations.

§Complexity

Runs in O(1), performs no allocations.

Source

pub fn owned_components( &self, ) -> impl DoubleEndedIterator<Item = OwnedComponent<MCL>> + ExactSizeIterator<Item = OwnedComponent<MCL>> + '_

Create an iterator over owned handles to the components of this path.

Stepping the iterator takes O(1) time and performs no memory allocations.

§Complexity

Runs in O(1), performs no allocations.

Source

pub fn suffix_owned_components( &self, i: usize, ) -> impl DoubleEndedIterator<Item = OwnedComponent<MCL>> + ExactSizeIterator<Item = OwnedComponent<MCL>> + '_

Create an iterator over owned handles to the components of this path, starting at the i-th component. If i is greater than or equal to the number of components, the iterator yields zero items.

Stepping the iterator takes O(1) time and performs no memory allocations.

§Complexity

Runs in O(1), performs no allocations.

Source

pub fn create_prefix(&self, length: usize) -> Option<Self>

Create a new path that consists of the first length components. More efficient than creating a new Path from scratch.

Returns None if length is greater than self.get_component_count().

§Complexity

Runs in O(1), performs no allocations.

Source

pub unsafe fn create_prefix_unchecked(&self, length: usize) -> Self

Create a new path that consists of the first length components. More efficient than creating a new Path from scratch.

§Safety

Undefined behaviour if length is greater than self.get_component_count(). May manifest directly, or at any later function invocation that operates on the resulting Path.

§Complexity

Runs in O(1), performs no allocations.

Source

pub fn all_prefixes(&self) -> impl DoubleEndedIterator<Item = Self> + '_

Create an iterator over all prefixes of this path (including th empty path and the path itself).

Stepping the iterator takes O(1) time and performs no memory allocations.

§Complexity

Runs in O(1), performs no allocations.

Source

pub fn is_prefix_of(&self, other: &Self) -> bool

Test whether this path is a prefix of the given path. Paths are always a prefix of themselves, and the empty path is a prefix of every path.

§Complexity

Runs in O(n), where n is the total length of the shorter of the two paths. Performs no allocations.

Source

pub fn is_prefixed_by(&self, other: &Self) -> bool

Test whether this path is prefixed by the given path. Paths are always a prefix of themselves.

§Complexity

Runs in O(n), where n is the total length of the shorter of the two paths. Performs no allocations.

Source

pub fn longest_common_prefix(&self, other: &Self) -> Self

Return the longest common prefix of this path and the given path.

§Complexity

Runs in O(n), where n is the total length of the shorter of the two paths. Performs a single allocation to create the return value.

Source

pub fn successor(&self) -> Option<Self>

Return the least path which is strictly greater than self, or return None if self is the greatest possible path.

§Complexity

Runs in O(n), where n is the total length of the shorter of the two paths. Performs a single allocation to create the return value.

Source

pub fn greater_but_not_prefixed(&self) -> Option<Self>

Return the least path that is strictly greater than self and which is not prefixed by self, or None if no such path exists.

§Complexity

Runs in O(n), where n is the total length of the shorter of the two paths. Performs a single allocation to create the return value.

Trait Implementations§

Source§

impl<'a, const MCL: usize, const MCC: usize, const MPL: usize> Arbitrary<'a> for Path<MCL, MCC, MPL>

Source§

fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self, ArbitraryError>

Generate an arbitrary value of Self from the given unstructured data. Read more
Source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
Source§

fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

impl<const MCL: usize, const MCC: usize, const MPL: usize> Clone for Path<MCL, MCC, MPL>

Source§

fn clone(&self) -> Path<MCL, MCC, MPL>

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<const MCL: usize, const MCC: usize, const MPL: usize> Debug for Path<MCL, MCC, MPL>

Source§

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

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

impl<const MCL: usize, const MCC: usize, const MPL: usize> Decodable for Path<MCL, MCC, MPL>

Source§

async fn decode<P>(producer: &mut P) -> Result<Self, DecodeError<P::Error>>
where P: BulkProducer<Item = u8>,

Decade a value to a bytestring in a specific way that is best described over at willowprotocol.org. Read more
Source§

impl<const MCL: usize, const MCC: usize, const MPL: usize> Decodable for Path<MCL, MCC, MPL>

Source§

fn decode<P>(producer: &mut P) -> Result<Self, DecodeError<P::Error>>
where P: BulkProducer<Item = u8>,

Decode a value to a bytestring in a specific way that is best described over at willowprotocol.org. Read more
Source§

impl<const MCL: usize, const MCC: usize, const MPL: usize> Encodable for Path<MCL, MCC, MPL>

Source§

async fn encode<C>(&self, consumer: &mut C) -> Result<(), C::Error>
where C: BulkConsumer<Item = u8>,

Encode a value to a bytestring in a specific way that is best described over at willowprotocol.org. Read more
Source§

impl<const MCL: usize, const MCC: usize, const MPL: usize> Encodable for Path<MCL, MCC, MPL>

Source§

fn encode<C>(&self, consumer: &mut C) -> Result<(), C::Error>
where C: BulkConsumer<Item = u8>,

Encode a value to a bytestring in a specific way that is best described over at willowprotocol.org. Read more
Source§

impl<const MCL: usize, const MCC: usize, const MPL: usize> Hash for Path<MCL, MCC, MPL>

Source§

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

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<const MCL: usize, const MCC: usize, const MPL: usize> Ord for Path<MCL, MCC, MPL>

Compare paths lexicogrphically, since that is the path ordering that the Willow spec always uses.

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

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

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

impl<const MCL: usize, const MCC: usize, const MPL: usize> PartialEq<RangeEnd<Path<MCL, MCC, MPL>>> for Path<MCL, MCC, MPL>

Source§

fn eq(&self, other: &RangeEnd<Path<MCL, MCC, MPL>>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const MCL: usize, const MCC: usize, const MPL: usize> PartialEq for Path<MCL, MCC, MPL>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const MCL: usize, const MCC: usize, const MPL: usize> PartialOrd<RangeEnd<Path<MCL, MCC, MPL>>> for Path<MCL, MCC, MPL>

Source§

fn partial_cmp(&self, other: &RangeEnd<Path<MCL, MCC, MPL>>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · 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 · 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 · 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 · 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<const MCL: usize, const MCC: usize, const MPL: usize> PartialOrd for Path<MCL, MCC, MPL>

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · 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 · 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 · 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 · 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<const MCL: usize, const MCC: usize, const MPL: usize> RelativeDecodable<Path<MCL, MCC, MPL>> for Path<MCL, MCC, MPL>

Source§

async fn relative_decode<Producer>( reference: &Path<MCL, MCC, MPL>, producer: &mut Producer, ) -> Result<Self, DecodeError<Producer::Error>>
where Producer: BulkProducer<Item = u8>, Self: Sized,

Decode a path relative to this path.

Definition

Source§

impl<const MCL: usize, const MCC: usize, const MPL: usize> RelativeDecodable<Path<MCL, MCC, MPL>> for Path<MCL, MCC, MPL>

Source§

fn relative_decode<Producer>( reference: &Path<MCL, MCC, MPL>, producer: &mut Producer, ) -> Result<Self, DecodeError<Producer::Error>>
where Producer: BulkProducer<Item = u8>, Self: Sized,

Decode a path relative to this path.

Definition

Source§

impl<const MCL: usize, const MCC: usize, const MPL: usize> RelativeEncodable<Path<MCL, MCC, MPL>> for Path<MCL, MCC, MPL>

Source§

async fn relative_encode<Consumer>( &self, reference: &Path<MCL, MCC, MPL>, consumer: &mut Consumer, ) -> Result<(), Consumer::Error>
where Consumer: BulkConsumer<Item = u8>,

Encode a path relative to another path.

Definition

Source§

impl<const MCL: usize, const MCC: usize, const MPL: usize> RelativeEncodable<Path<MCL, MCC, MPL>> for Path<MCL, MCC, MPL>

Source§

fn relative_encode<Consumer>( &self, reference: &Path<MCL, MCC, MPL>, consumer: &mut Consumer, ) -> Result<(), Consumer::Error>
where Consumer: BulkConsumer<Item = u8>,

Encode a path relative to another path.

Definition

Source§

impl<const MCL: usize, const MCC: usize, const MPL: usize> Eq for Path<MCL, MCC, MPL>

Auto Trait Implementations§

§

impl<const MCL: usize, const MCC: usize, const MPL: usize> !Freeze for Path<MCL, MCC, MPL>

§

impl<const MCL: usize, const MCC: usize, const MPL: usize> RefUnwindSafe for Path<MCL, MCC, MPL>

§

impl<const MCL: usize, const MCC: usize, const MPL: usize> Send for Path<MCL, MCC, MPL>

§

impl<const MCL: usize, const MCC: usize, const MPL: usize> Sync for Path<MCL, MCC, MPL>

§

impl<const MCL: usize, const MCC: usize, const MPL: usize> Unpin for Path<MCL, MCC, MPL>

§

impl<const MCL: usize, const MCC: usize, const MPL: usize> UnwindSafe for Path<MCL, MCC, MPL>

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.