Skip to content

Commit

Permalink
feat(ini): implement IntoIterator for Ini (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Sep 8, 2023
1 parent 02559c3 commit 1b67ac6
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use std::{

use cfg_if::cfg_if;
use ordered_multimap::{
list_ordered_multimap::{Entry, Iter, IterMut, OccupiedEntry, VacantEntry},
list_ordered_multimap::{Entry, IntoIter, Iter, IterMut, OccupiedEntry, VacantEntry},
ListOrderedMultimap,
};
#[cfg(feature = "case-insensitive")]
Expand Down Expand Up @@ -976,6 +976,29 @@ impl DoubleEndedIterator for SectionIterMut<'_> {
}
}

/// Iterator for traversing sections
pub struct SectionIntoIter {
inner: IntoIter<SectionKey, Properties>,
}

impl Iterator for SectionIntoIter {
type Item = (SectionKey, Properties);

fn next(&mut self) -> Option<Self::Item> {
self.inner.next()
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
}
}

impl DoubleEndedIterator for SectionIntoIter {
fn next_back(&mut self) -> Option<Self::Item> {
self.inner.next_back()
}
}

impl<'a> Ini {
/// Immutable iterate though sections
pub fn iter(&'a self) -> SectionIter<'a> {
Expand Down Expand Up @@ -1016,6 +1039,17 @@ impl<'a> IntoIterator for &'a mut Ini {
}
}

impl IntoIterator for Ini {
type IntoIter = SectionIntoIter;
type Item = (SectionKey, Properties);

fn into_iter(self) -> Self::IntoIter {
SectionIntoIter {
inner: self.sections.into_iter(),
}
}
}

// Ini parser
struct Parser<'a> {
ch: Option<char>,
Expand Down

0 comments on commit 1b67ac6

Please sign in to comment.