Skip to content

Commit 1b67ac6

Browse files
committed
feat(ini): implement IntoIterator for Ini (#114)
1 parent 02559c3 commit 1b67ac6

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/lib.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use std::{
5555

5656
use cfg_if::cfg_if;
5757
use ordered_multimap::{
58-
list_ordered_multimap::{Entry, Iter, IterMut, OccupiedEntry, VacantEntry},
58+
list_ordered_multimap::{Entry, IntoIter, Iter, IterMut, OccupiedEntry, VacantEntry},
5959
ListOrderedMultimap,
6060
};
6161
#[cfg(feature = "case-insensitive")]
@@ -976,6 +976,29 @@ impl DoubleEndedIterator for SectionIterMut<'_> {
976976
}
977977
}
978978

979+
/// Iterator for traversing sections
980+
pub struct SectionIntoIter {
981+
inner: IntoIter<SectionKey, Properties>,
982+
}
983+
984+
impl Iterator for SectionIntoIter {
985+
type Item = (SectionKey, Properties);
986+
987+
fn next(&mut self) -> Option<Self::Item> {
988+
self.inner.next()
989+
}
990+
991+
fn size_hint(&self) -> (usize, Option<usize>) {
992+
self.inner.size_hint()
993+
}
994+
}
995+
996+
impl DoubleEndedIterator for SectionIntoIter {
997+
fn next_back(&mut self) -> Option<Self::Item> {
998+
self.inner.next_back()
999+
}
1000+
}
1001+
9791002
impl<'a> Ini {
9801003
/// Immutable iterate though sections
9811004
pub fn iter(&'a self) -> SectionIter<'a> {
@@ -1016,6 +1039,17 @@ impl<'a> IntoIterator for &'a mut Ini {
10161039
}
10171040
}
10181041

1042+
impl IntoIterator for Ini {
1043+
type IntoIter = SectionIntoIter;
1044+
type Item = (SectionKey, Properties);
1045+
1046+
fn into_iter(self) -> Self::IntoIter {
1047+
SectionIntoIter {
1048+
inner: self.sections.into_iter(),
1049+
}
1050+
}
1051+
}
1052+
10191053
// Ini parser
10201054
struct Parser<'a> {
10211055
ch: Option<char>,

0 commit comments

Comments
 (0)