added IntoIterator to set and map
This commit is contained in:
@@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with range_bounds_map. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use std::collections::btree_map::IntoValues;
|
||||
use std::collections::BTreeMap;
|
||||
use std::fmt::Debug;
|
||||
use std::iter::once;
|
||||
@@ -1452,6 +1453,38 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, K, V> IntoIterator for RangeBoundsMap<I, K, V>
|
||||
where
|
||||
K: RangeBounds<I>,
|
||||
I: Ord + Clone,
|
||||
{
|
||||
type Item = (K, V);
|
||||
type IntoIter = IntoIter<I, K, V>;
|
||||
#[trivial]
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
return IntoIter {
|
||||
inner: self.starts.into_values(),
|
||||
};
|
||||
}
|
||||
}
|
||||
/// An owning iterator over the entries of a `RangeBoundsMap`.
|
||||
///
|
||||
/// This `struct` is created by the [`into_iter`] method on
|
||||
/// [`RangeBoundsMap`] (provided by the [`IntoIterator`] trait). See
|
||||
/// its documentation for more.
|
||||
///
|
||||
/// [`into_iter`]: IntoIterator::into_iter
|
||||
/// [`IntoIterator`]: core::iter::IntoIterator
|
||||
pub struct IntoIter<I, K, V> {
|
||||
inner: IntoValues<BoundOrd<I>, (K, V)>,
|
||||
}
|
||||
impl<I, K, V> Iterator for IntoIter<I, K, V> {
|
||||
type Item = (K, V);
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.inner.next()
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, K, V> Default for RangeBoundsMap<I, K, V>
|
||||
where
|
||||
I: PartialOrd,
|
||||
|
||||
@@ -23,6 +23,7 @@ use std::ops::{Bound, RangeBounds};
|
||||
use labels::{tested, trivial};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::range_bounds_map::IntoIter as MapIntoIter;
|
||||
use crate::{
|
||||
OverlapError, OverlapOrTryFromBoundsError, RangeBoundsMap, TryFromBounds,
|
||||
TryFromBoundsError,
|
||||
@@ -802,6 +803,37 @@ where
|
||||
return output;
|
||||
}
|
||||
}
|
||||
impl<I, K> IntoIterator for RangeBoundsSet<I, K>
|
||||
where
|
||||
K: RangeBounds<I>,
|
||||
I: Ord + Clone,
|
||||
{
|
||||
type Item = K;
|
||||
type IntoIter = IntoIter<I, K>;
|
||||
#[trivial]
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
return IntoIter {
|
||||
inner: self.map.into_iter(),
|
||||
};
|
||||
}
|
||||
}
|
||||
/// An owning iterator over the entries of a `RangeBoundsSet`.
|
||||
///
|
||||
/// This `struct` is created by the [`into_iter`] method on
|
||||
/// [`RangeBoundsSet`] (provided by the [`IntoIterator`] trait). See
|
||||
/// its documentation for more.
|
||||
///
|
||||
/// [`into_iter`]: IntoIterator::into_iter
|
||||
/// [`IntoIterator`]: core::iter::IntoIterator
|
||||
pub struct IntoIter<I, K> {
|
||||
inner: MapIntoIter<I, K, ()>,
|
||||
}
|
||||
impl<I, K> Iterator for IntoIter<I, K> {
|
||||
type Item = K;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.inner.next().map(first)
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, K> Default for RangeBoundsSet<I, K>
|
||||
where
|
||||
@@ -814,3 +846,7 @@ where
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn first<A, B>((a, _): (A, B)) -> A {
|
||||
a
|
||||
}
|
||||
|
||||
@@ -8,10 +8,13 @@
|
||||
logic based RangeBounds functions
|
||||
- make an expand function to go RangeBounds -> (Bound, Bound) rather
|
||||
than doing it manually everywhere
|
||||
- rename overwrite to insert_forceful
|
||||
- replace instances of |(key, _)| with fn first()
|
||||
|
||||
# Documentation
|
||||
|
||||
- replace `RangeBounds` with `K` where applicatble in docs
|
||||
- replace rust types URL links with direct rust links
|
||||
|
||||
# features
|
||||
|
||||
@@ -37,6 +40,7 @@
|
||||
- remove most rustfmt::skips and cargo fmt
|
||||
- check toml meta-data, github meta-data and readme opener
|
||||
- copy map to set again
|
||||
- review todo.txt
|
||||
- copy readme to lib.rs docs again
|
||||
- take a look around idiomatic rust for a bit first
|
||||
- run is_labelled again and check they are accurate
|
||||
|
||||
Reference in New Issue
Block a user