events: Implement {From,Into}Iterator for DirectEventContent

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

View File

@ -3,7 +3,7 @@
//! [`m.direct`]: https://spec.matrix.org/latest/client-server-api/#mdirect //! [`m.direct`]: https://spec.matrix.org/latest/client-server-api/#mdirect
use std::{ use std::{
collections::BTreeMap, collections::{btree_map, BTreeMap},
ops::{Deref, DerefMut}, ops::{Deref, DerefMut},
}; };
@ -37,6 +37,24 @@ impl DerefMut for DirectEventContent {
} }
} }
impl IntoIterator for DirectEventContent {
type Item = (OwnedUserId, Vec<OwnedRoomId>);
type IntoIter = btree_map::IntoIter<OwnedUserId, Vec<OwnedRoomId>>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
impl FromIterator<(OwnedUserId, Vec<OwnedRoomId>)> for DirectEventContent {
fn from_iter<T>(iter: T) -> Self
where
T: IntoIterator<Item = (OwnedUserId, Vec<OwnedRoomId>)>,
{
Self(BTreeMap::from_iter(iter))
}
}
#[cfg(all(test, feature = "rand"))] #[cfg(all(test, feature = "rand"))]
mod tests { mod tests {
use std::collections::BTreeMap; use std::collections::BTreeMap;