vec_vec/
lib.rs

1#![doc = include_str!("../README.md")]
2
3mod lending_iter;
4mod lending_iter_mut;
5mod popping_iter;
6mod trivial_last_entry;
7
8pub use lending_iter::LendingIter;
9pub use lending_iter_mut::LendingIterMut;
10pub use popping_iter::PoppingIter;
11pub use trivial_last_entry::TrivialLastEntry;
12
13/// An [extension trait] for `Vec<Vec<T>>`.
14///
15/// [extension trait]: https://doc.rust-lang.org/book/ch10-02-traits.html#extending-a-trait
16pub trait VecVecExt {
17    /// The type `T` of the items contained in the `Vec<Vec<T>>`.
18    type Item;
19
20    /// Returns a [`PoppingIter`] over the `Vec<Vec<T>>`.
21    fn popping_iter(&mut self) -> PoppingIter<'_, Self::Item>;
22
23    /// Returns a [lending iterator] over the mutable references to the elements of `Vec<Vec<T>>`.
24    ///
25    /// [lending iterator]: https://blog.rust-lang.org/2022/10/28/gats-stabilization.html#what-are-gats
26    fn lending_iter_mut(&mut self) -> LendingIterMut<'_, Self::Item>;
27
28    /// Returns a [lending iterator] over the shared references to the elements of `Vec<Vec<T>>`.
29    fn lending_iter(&self) -> LendingIter<'_, Self::Item>;
30
31    fn trivial_last_entry(&mut self) -> Option<TrivialLastEntry<'_, Self::Item>>;
32}
33
34impl<T> VecVecExt for Vec<Vec<T>> {
35    type Item = T;
36
37    fn popping_iter(&mut self) -> PoppingIter<'_, Self::Item> {
38        PoppingIter(self)
39    }
40
41    fn lending_iter_mut(&mut self) -> LendingIterMut<'_, Self::Item> {
42        LendingIterMut::new(self)
43    }
44
45    fn lending_iter(&self) -> LendingIter<'_, Self::Item> {
46        LendingIter::new(self)
47    }
48
49    fn trivial_last_entry(&mut self) -> Option<TrivialLastEntry<'_, Self::Item>> {
50        TrivialLastEntry::new(self)
51    }
52}