pub struct ZipList<T> { /* private fields */ }Expand description
A ZipList can be thought of as a linked list with a hole punched in it to mark a single element that currently holds focus (though in practice it is implemented using a VecDeque for efficiency purposes). By convention, the main element is the first element in the stack (regardless of focus). Focusing operations do not reorder the elements of the stack or the resulting Vec that can be obtained from calling ZipList::flatten.
This is a zipper over a VecDeque. Many of the methods that mutate the structure of the ZipList return back a mutable reference so that they are able to be chained.
Implementations§
Source§impl<T> ZipList<T>
impl<T> ZipList<T>
Sourcepub fn new<I, J>(up: I, focus: T, down: J) -> Selfwhere
I: IntoIterator<Item = T>,
J: IntoIterator<Item = T>,
pub fn new<I, J>(up: I, focus: T, down: J) -> Selfwhere
I: IntoIterator<Item = T>,
J: IntoIterator<Item = T>,
Create a new ZipList specifying the focused element and and elements above and below it.
Sourcepub fn try_from_iter<I>(iter: I) -> Option<Self>where
I: IntoIterator<Item = T>,
pub fn try_from_iter<I>(iter: I) -> Option<Self>where
I: IntoIterator<Item = T>,
For an iterator of at least one element, the first element will be focused and all remaining elements will be placed after it. For an empty iterator, return None.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Always false: a ZipList always has at least one focused element.
Sourcepub fn iter(&self) -> Iter<'_, T> ⓘ
pub fn iter(&self) -> Iter<'_, T> ⓘ
Provide an iterator over this stack iterating over up, focus and then down.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
Provide an iterator over this stack iterating over up, focus and then down with mutable references.
Sourcepub fn unravel(&self) -> impl Iterator<Item = &T>
pub fn unravel(&self) -> impl Iterator<Item = &T>
Iterate over the clients in this stack from the the focused element down through the stack.
Sourcepub fn flatten(self) -> Vec<T>
pub fn flatten(self) -> Vec<T>
Flatten a ZipList into a Vector, losing the information of which element is focused.
pub fn last_mut(&mut self) -> &mut T
Sourcepub fn swap_focus_and_head(&mut self) -> &mut Self
pub fn swap_focus_and_head(&mut self) -> &mut Self
Swap the current head element with the focused element in the stack order. Focus stays with the original focused element.
Sourcepub fn rotate_focus_to_head(&mut self) -> &mut Self
pub fn rotate_focus_to_head(&mut self) -> &mut Self
Rotate the ZipList until the current focused element is in the head position
Sourcepub fn focus_head(&mut self) -> &mut Self
pub fn focus_head(&mut self) -> &mut Self
Move focus to the element in the head position
Sourcepub fn focus_tail(&mut self) -> &mut Self
pub fn focus_tail(&mut self) -> &mut Self
Move focus to the element in the head position
Sourcepub fn insert(&mut self, t: T) -> &mut Self
pub fn insert(&mut self, t: T) -> &mut Self
Insert the given element in place of the current focus, pushing the current focus down the ZipList.
Sourcepub fn remove_focused(self) -> (T, Option<Self>)
pub fn remove_focused(self) -> (T, Option<Self>)
Remove the focused element of this ZipList. If this was the only element then the stack is dropped and None is returned.
Sourcepub fn remove_focused_unchecked(&mut self) -> T
pub fn remove_focused_unchecked(&mut self) -> T
Sourcepub fn remove_where_with_default(
&mut self,
pred: impl Fn(&T) -> bool,
default: impl Fn() -> T,
) -> Option<T>
pub fn remove_where_with_default( &mut self, pred: impl Fn(&T) -> bool, default: impl Fn() -> T, ) -> Option<T>
Remove the first element that matches the given predicate function. If doing so would
remove the last element of the ZipList then default_focus is called to ensure that there
is a single element remaining as the current focus.
Sourcepub fn map<F, U>(self, f: F) -> ZipList<U>where
F: Fn(T) -> U,
pub fn map<F, U>(self, f: F) -> ZipList<U>where
F: Fn(T) -> U,
Map a function over all elements in this ZipList, returning a new one.
Sourcepub fn filter<F>(self, f: F) -> Option<Self>
pub fn filter<F>(self, f: F) -> Option<Self>
Retain only elements which satisfy the given predicate. If the focused element is removed then focus shifts to the first remaining element after it, if there are no elements after then focus moves to the first remaining element before. If no elements satisfy the predicate then None is returned.
pub fn filter_unchecked<F>(&mut self, f: F)
Sourcepub fn reverse(&mut self) -> &mut Self
pub fn reverse(&mut self) -> &mut Self
Reverse the ordering of a ZipList (up becomes down) while maintaining focus.
Sourcepub fn focus_up(&mut self) -> &mut Self
pub fn focus_up(&mut self) -> &mut Self
Move focus from the current element up the stack, wrapping to the bottom if focus is already at the top.
Sourcepub fn focus_down(&mut self) -> &mut Self
pub fn focus_down(&mut self) -> &mut Self
Move focus from the current element down the stack, wrapping to the top if focus is already at the bottom.
Sourcepub fn focus_element_by<F>(&mut self, f: F) -> bool
pub fn focus_element_by<F>(&mut self, f: F) -> bool
Focus the first element found matching the given predicate function.
Returns true if the focused element changed. If no matching elements are found, the ZipList will be left in its original state and false is returned.
Sourcepub fn focus_element_by_mut<F>(&mut self, f: F) -> bool
pub fn focus_element_by_mut<F>(&mut self, f: F) -> bool
Focus the first element found matching the given predicate function.
If no matching elements are found, the ZipList will be left in its original state.
Sourcepub fn swap_up(&mut self) -> &mut Self
pub fn swap_up(&mut self) -> &mut Self
Swap the focused element with the one above, wrapping from top to bottom. The currently focused element is maintained by this operation.
Sourcepub fn swap_down(&mut self) -> &mut Self
pub fn swap_down(&mut self) -> &mut Self
Swap the focused element with the one below, wrapping from top to bottom. The currently focused element is maintained by this operation.
Sourcepub fn rotate_up(&mut self) -> &mut Self
pub fn rotate_up(&mut self) -> &mut Self
Rotate all elements of the stack forward, wrapping from top to bottom. The currently focused element in the stack is maintained by this operation.
Sourcepub fn rotate_down(&mut self) -> &mut Self
pub fn rotate_down(&mut self) -> &mut Self
Rotate all elements of the stack back, wrapping from bottom to top. The currently focused element in the stack is maintained by this operation.
Trait Implementations§
Source§impl<'a, T> IntoIterator for &'a ZipList<T>
impl<'a, T> IntoIterator for &'a ZipList<T>
Source§impl<'a, T> IntoIterator for &'a mut ZipList<T>
impl<'a, T> IntoIterator for &'a mut ZipList<T>
Source§impl<T> IntoIterator for ZipList<T>
impl<T> IntoIterator for ZipList<T>
impl<T: Eq> Eq for ZipList<T>
impl<T> StructuralPartialEq for ZipList<T>
Auto Trait Implementations§
impl<T> Freeze for ZipList<T>where
T: Freeze,
impl<T> RefUnwindSafe for ZipList<T>where
T: RefUnwindSafe,
impl<T> Send for ZipList<T>where
T: Send,
impl<T> Sync for ZipList<T>where
T: Sync,
impl<T> Unpin for ZipList<T>where
T: Unpin,
impl<T> UnwindSafe for ZipList<T>where
T: UnwindSafe,
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.