implement `IntoIterator` for `Events`

This commit is contained in:
Matthew Nicholson 2019-03-31 01:55:24 -04:00
parent d4aee284e5
commit 6f1021b4a3
1 changed files with 18 additions and 0 deletions

View File

@ -54,6 +54,24 @@ macro_rules! declare_events_struct {
}
}
impl<T: 'static> IntoIterator for Events<T> {
type Item = (&'static str, T);
type IntoIter = Box<dyn Iterator<Item = Self::Item>>;
fn into_iter(mut self) -> Self::IntoIter {
Box::new(
iter::empty()
$(
.chain(
iter::once(self.$name.take())
.filter(|value| value.is_some())
.map(|value| (stringify!($name), value.unwrap()))
)
)*
)
}
}
impl<T> Default for Events<T> {
fn default() -> Self {
Events {