events: Implement {From,Into}Iterator for ReceiptEventContent

This commit is contained in:
Jonas Platte 2023-02-22 16:41:54 +01:00
parent 53f9cf52ed
commit 54d27f1083
No known key found for this signature in database
GPG Key ID: AAA7A61F696C3E0C

View File

@ -5,7 +5,7 @@
mod receipt_thread_serde; mod receipt_thread_serde;
use std::{ use std::{
collections::BTreeMap, collections::{btree_map, BTreeMap},
ops::{Deref, DerefMut}, ops::{Deref, DerefMut},
}; };
@ -54,6 +54,24 @@ impl DerefMut for ReceiptEventContent {
} }
} }
impl IntoIterator for ReceiptEventContent {
type Item = (OwnedEventId, Receipts);
type IntoIter = btree_map::IntoIter<OwnedEventId, Receipts>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
impl FromIterator<(OwnedEventId, Receipts)> for ReceiptEventContent {
fn from_iter<T>(iter: T) -> Self
where
T: IntoIterator<Item = (OwnedEventId, Receipts)>,
{
Self(BTreeMap::from_iter(iter))
}
}
/// A collection of receipts. /// A collection of receipts.
pub type Receipts = BTreeMap<ReceiptType, UserReceipts>; pub type Receipts = BTreeMap<ReceiptType, UserReceipts>;