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>
impl<const MCL: usize, const MCC: usize, const MPL: usize> Path<MCL, MCC, MPL>
Sourcepub fn new_empty() -> Self
pub fn new_empty() -> Self
Construct an empty path, i.e., a path of zero components.
§Complexity
Runs in O(1), performs no allocations.
Sourcepub fn new_singleton(comp: Component<'_, MCL>) -> Result<Self, InvalidPathError>
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.
Sourcepub fn new_from_iter<'a, I>(
total_length: usize,
iter: &mut I,
) -> Result<Self, InvalidPathError>where
I: ExactSizeIterator<Item = Component<'a, MCL>>,
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.
Sourcepub fn new_from_slice(
components: &[Component<'_, MCL>],
) -> Result<Self, InvalidPathError>
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.
Sourcepub fn append(&self, comp: Component<'_, MCL>) -> Result<Self, InvalidPathError>
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.
Sourcepub fn append_slice(
&self,
components: &[Component<'_, MCL>],
) -> Result<Self, InvalidPathError>
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.
Sourcepub fn get_component_count(&self) -> usize
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.
Sourcepub fn get_path_length(&self) -> usize
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.
Sourcepub fn get_component(&self, i: usize) -> Option<Component<'_, MCL>>
pub fn get_component(&self, i: usize) -> Option<Component<'_, MCL>>
Sourcepub fn get_owned_component(&self, i: usize) -> Option<OwnedComponent<MCL>>
pub fn get_owned_component(&self, i: usize) -> Option<OwnedComponent<MCL>>
Sourcepub fn components(
&self,
) -> impl DoubleEndedIterator<Item = Component<'_, MCL>> + ExactSizeIterator<Item = Component<'_, MCL>>
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.
Sourcepub fn suffix_components(
&self,
i: usize,
) -> impl DoubleEndedIterator<Item = Component<'_, MCL>> + ExactSizeIterator<Item = Component<'_, MCL>>
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.
Sourcepub fn owned_components(
&self,
) -> impl DoubleEndedIterator<Item = OwnedComponent<MCL>> + ExactSizeIterator<Item = OwnedComponent<MCL>> + '_
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.
Sourcepub fn suffix_owned_components(
&self,
i: usize,
) -> impl DoubleEndedIterator<Item = OwnedComponent<MCL>> + ExactSizeIterator<Item = OwnedComponent<MCL>> + '_
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.
Sourcepub fn create_prefix(&self, length: usize) -> Option<Self>
pub fn create_prefix(&self, length: usize) -> Option<Self>
Sourcepub unsafe fn create_prefix_unchecked(&self, length: usize) -> Self
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.
Sourcepub fn all_prefixes(&self) -> impl DoubleEndedIterator<Item = Self> + '_
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.
Sourcepub fn is_prefix_of(&self, other: &Self) -> bool
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.
Sourcepub fn is_prefixed_by(&self, other: &Self) -> bool
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.
Sourcepub fn longest_common_prefix(&self, other: &Self) -> Self
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.
Sourcepub fn successor(&self) -> Option<Self>
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.
Sourcepub fn greater_but_not_prefixed(&self) -> Option<Self>
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>
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>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self, ArbitraryError>
Self from the given unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl<const MCL: usize, const MCC: usize, const MPL: usize> Decodable for Path<MCL, MCC, MPL>
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>,
async fn decode<P>(producer: &mut P) -> Result<Self, DecodeError<P::Error>>where
P: BulkProducer<Item = u8>,
Source§impl<const MCL: usize, const MCC: usize, const MPL: usize> Decodable for Path<MCL, MCC, MPL>
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>,
fn decode<P>(producer: &mut P) -> Result<Self, DecodeError<P::Error>>where
P: BulkProducer<Item = u8>,
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.
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§impl<const MCL: usize, const MCC: usize, const MPL: usize> PartialEq<RangeEnd<Path<MCL, MCC, MPL>>> for Path<MCL, MCC, MPL>
impl<const MCL: usize, const MCC: usize, const MPL: usize> PartialEq<RangeEnd<Path<MCL, MCC, MPL>>> for Path<MCL, MCC, MPL>
Source§impl<const MCL: usize, const MCC: usize, const MPL: usize> PartialOrd<RangeEnd<Path<MCL, MCC, MPL>>> for Path<MCL, MCC, MPL>
impl<const MCL: usize, const MCC: usize, const MPL: usize> PartialOrd<RangeEnd<Path<MCL, MCC, MPL>>> for Path<MCL, MCC, MPL>
Source§impl<const MCL: usize, const MCC: usize, const MPL: usize> PartialOrd for Path<MCL, MCC, MPL>
impl<const MCL: usize, const MCC: usize, const MPL: usize> PartialOrd for Path<MCL, MCC, MPL>
Source§impl<const MCL: usize, const MCC: usize, const MPL: usize> RelativeDecodable<Path<MCL, MCC, MPL>> for Path<MCL, MCC, MPL>
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>>
async fn relative_decode<Producer>( reference: &Path<MCL, MCC, MPL>, producer: &mut Producer, ) -> Result<Self, DecodeError<Producer::Error>>
Decode a path relative to this path.
Source§impl<const MCL: usize, const MCC: usize, const MPL: usize> RelativeDecodable<Path<MCL, MCC, MPL>> for Path<MCL, MCC, MPL>
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>>
fn relative_decode<Producer>( reference: &Path<MCL, MCC, MPL>, producer: &mut Producer, ) -> Result<Self, DecodeError<Producer::Error>>
Decode a path relative to this path.
Source§impl<const MCL: usize, const MCC: usize, const MPL: usize> RelativeEncodable<Path<MCL, MCC, MPL>> for Path<MCL, MCC, MPL>
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>,
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.
Source§impl<const MCL: usize, const MCC: usize, const MPL: usize> RelativeEncodable<Path<MCL, MCC, MPL>> for Path<MCL, MCC, MPL>
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>,
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.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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