pub trait ZipperMoving: Zipper {
Show 24 methods
// Required methods
fn path(&self) -> &[u8] ⓘ;
fn val_count(&self) -> usize;
fn descend_to<K: AsRef<[u8]>>(&mut self, k: K);
fn ascend(&mut self, steps: usize) -> bool;
fn ascend_until(&mut self) -> bool;
fn ascend_until_branch(&mut self) -> bool;
// Provided methods
fn at_root(&self) -> bool { ... }
fn reset(&mut self) { ... }
fn move_to_path<K: AsRef<[u8]>>(&mut self, path: K) -> usize { ... }
fn descend_to_check<K: AsRef<[u8]>>(&mut self, k: K) -> bool { ... }
fn descend_to_existing<K: AsRef<[u8]>>(&mut self, k: K) -> usize { ... }
fn descend_to_val<K: AsRef<[u8]>>(&mut self, k: K) -> usize { ... }
fn descend_to_value<K: AsRef<[u8]>>(&mut self, k: K) -> usize { ... }
fn descend_to_byte(&mut self, k: u8) { ... }
fn descend_to_existing_byte(&mut self, k: u8) -> bool { ... }
fn descend_indexed_byte(&mut self, idx: usize) -> bool { ... }
fn descend_indexed_branch(&mut self, idx: usize) -> bool { ... }
fn descend_first_byte(&mut self) -> bool { ... }
fn descend_last_byte(&mut self) -> bool { ... }
fn descend_until(&mut self) -> bool { ... }
fn ascend_byte(&mut self) -> bool { ... }
fn to_next_sibling_byte(&mut self) -> bool { ... }
fn to_prev_sibling_byte(&mut self) -> bool { ... }
fn to_next_step(&mut self) -> bool { ... }
}Expand description
An interface to enable moving a zipper around the trie and inspecting paths
§Terminology:
A zipper’s root is a point in the trie above which the zipper cannot ascend. A zipper permits access to a subtrie descending from its root, but that subtrie may be a part of a supertrie that the zipper is unable to access.
A zipper’s origin is always equal-to-or-above the zipper’s root. The position of the origin depends on how the zipper was created, and the origin will never be below the root. The origin of a given zipper will never change.
Required Methods§
Sourcefn val_count(&self) -> usize
fn val_count(&self) -> usize
Returns the total number of values contained at and below the zipper’s focus, including the focus itself
WARNING: This is not a cheap method. It may have an order-N cost
Sourcefn descend_to<K: AsRef<[u8]>>(&mut self, k: K)
fn descend_to<K: AsRef<[u8]>>(&mut self, k: K)
Moves the zipper deeper into the trie, to the key specified relative to the current zipper focus
Sourcefn ascend(&mut self, steps: usize) -> bool
fn ascend(&mut self, steps: usize) -> bool
Ascends the zipper steps steps. Returns true if the zipper sucessfully moved steps
If the root is fewer than n steps from the zipper’s position, then this method will stop at
the root and return false
Sourcefn ascend_until(&mut self) -> bool
fn ascend_until(&mut self) -> bool
Ascends the zipper to the nearest upstream branch point or value. Returns true if the zipper
focus moved upwards, otherwise returns false if the zipper was already at the root
NOTE: A default implementation could be provided, but all current zippers have more optimal native implementations.
Sourcefn ascend_until_branch(&mut self) -> bool
fn ascend_until_branch(&mut self) -> bool
Ascends the zipper to the nearest upstream branch point, skipping over values along the way. Returns
true if the zipper focus moved upwards, otherwise returns false if the zipper was already at the
root
NOTE: A default implementation could be provided, but all current zippers have more optimal native implementations.
Provided Methods§
Sourcefn at_root(&self) -> bool
fn at_root(&self) -> bool
Returns true if the zipper’s focus is at its root, and it cannot ascend further, otherwise returns false
Sourcefn move_to_path<K: AsRef<[u8]>>(&mut self, path: K) -> usize
fn move_to_path<K: AsRef<[u8]>>(&mut self, path: K) -> usize
Moves the zipper’s focus to a specific location specified by path, relative to the zipper’s root
Returns the number of bytes shared between the old and new location
Sourcefn descend_to_check<K: AsRef<[u8]>>(&mut self, k: K) -> bool
fn descend_to_check<K: AsRef<[u8]>>(&mut self, k: K) -> bool
Fused descend_to and path_exists. Moves the
focus and returns whether or not the path exists at the new focus location
Sourcefn descend_to_existing<K: AsRef<[u8]>>(&mut self, k: K) -> usize
fn descend_to_existing<K: AsRef<[u8]>>(&mut self, k: K) -> usize
Moves the zipper deeper into the trie, following the path specified by k, relative to the current
zipper focus. Descent stops at the point where the path does not exist
Returns the number of bytes descended along the path. The zipper’s focus will always be on an existing path after this method returns, unless the method was called with the focus on a non-existent path.
Sourcefn descend_to_val<K: AsRef<[u8]>>(&mut self, k: K) -> usize
fn descend_to_val<K: AsRef<[u8]>>(&mut self, k: K) -> usize
Moves the zipper deeper into the trie, following the path specified by k, relative to the current
zipper focus. Descent stops if a value is encountered or if the path ceases to exist.
Returns the number of bytes descended along the path.
If the focus is already on a value, this method will descend to the next value along the path.
Sourcefn descend_to_value<K: AsRef<[u8]>>(&mut self, k: K) -> usize
👎Deprecated
fn descend_to_value<K: AsRef<[u8]>>(&mut self, k: K) -> usize
Deprecated alias for ZipperMoving::descend_to_val
Sourcefn descend_to_byte(&mut self, k: u8)
fn descend_to_byte(&mut self, k: u8)
Moves the zipper one byte deeper into the trie. Identical in effect to descend_to with a 1-byte key argument
Sourcefn descend_to_existing_byte(&mut self, k: u8) -> bool
fn descend_to_existing_byte(&mut self, k: u8) -> bool
Moves the zipper one byte deeper into the trie, if the specified path byte exists in the child_mask.
Returns true if the zipper’s focus moved and false if it is still at the original location.
Sourcefn descend_indexed_byte(&mut self, idx: usize) -> bool
fn descend_indexed_byte(&mut self, idx: usize) -> bool
Descends the zipper’s focus one byte into a child branch uniquely identified by child_idx
child_idx must within the range 0..child_count() or this method will do nothing and return false
WARNING: The branch represented by a given index is not guaranteed to be stable across modifications to the trie. This method should only be used as part of a directed traversal operation, but index-based paths may not be stored as locations within the trie.
Sourcefn descend_indexed_branch(&mut self, idx: usize) -> bool
👎Deprecated
fn descend_indexed_branch(&mut self, idx: usize) -> bool
A deprecated alias for ZipperMoving::descend_indexed_byte
Sourcefn descend_first_byte(&mut self) -> bool
fn descend_first_byte(&mut self) -> bool
Descends the zipper’s focus one step into the first child branch in a depth-first traversal
NOTE: This method should have identical behavior to passing 0 to descend_indexed_byte,
although with less overhead
Sourcefn descend_last_byte(&mut self) -> bool
fn descend_last_byte(&mut self) -> bool
Descends the zipper’s focus one step into the last child branch
NOTE: This method should have identical behavior to passing child_count() - 1 to descend_indexed_byte,
although with less overhead
Sourcefn descend_until(&mut self) -> bool
fn descend_until(&mut self) -> bool
Descends the zipper’s focus until a branch or a value is encountered. Returns true if the focus
moved otherwise returns false
If there is a value at the focus, the zipper will descend to the next value or branch, however the zipper will not descend further if this method is called with the focus already on a branch.
Does nothing and returns false if the zipper’s focus is on a non-existent path.
Sourcefn ascend_byte(&mut self) -> bool
fn ascend_byte(&mut self) -> bool
Ascends the zipper up a single byte. Equivalent to passing 1 to ascend
Sourcefn to_next_sibling_byte(&mut self) -> bool
fn to_next_sibling_byte(&mut self) -> bool
Moves the zipper’s focus to the next sibling byte with the same parent
Returns true if the focus was moved. If the focus is already on the last byte among its siblings,
this method returns false, leving the focus unmodified.
This method is equivalent to calling ZipperMoving::ascend with 1, followed by ZipperMoving::descend_indexed_byte
where the index passed is 1 more than the index of the current focus position.
Sourcefn to_prev_sibling_byte(&mut self) -> bool
fn to_prev_sibling_byte(&mut self) -> bool
Moves the zipper’s focus to the previous sibling byte with the same parent
Returns true if the focus was moved. If the focus is already on the first byte among its siblings,
this method returns false, leving the focus unmodified.
This method is equivalent to calling Self::ascend with 1, followed by Self::descend_indexed_byte
where the index passed is 1 less than the index of the current focus position.
Sourcefn to_next_step(&mut self) -> bool
fn to_next_step(&mut self) -> bool
Advances the zipper to visit every existing path within the trie in a depth-first order
Returns true if the position of the zipper has moved, or false if the zipper has returned
to the root
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.