From 53f9cf52ed9f1b680467f8afa7e67d30d15915ba Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 22 Feb 2023 16:41:19 +0100 Subject: [PATCH] events: Implement {From,Into}Iterator for DirectEventContent --- crates/ruma-common/src/events/direct.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/ruma-common/src/events/direct.rs b/crates/ruma-common/src/events/direct.rs index 934b961d..1ab315fc 100644 --- a/crates/ruma-common/src/events/direct.rs +++ b/crates/ruma-common/src/events/direct.rs @@ -3,7 +3,7 @@ //! [`m.direct`]: https://spec.matrix.org/latest/client-server-api/#mdirect use std::{ - collections::BTreeMap, + collections::{btree_map, BTreeMap}, ops::{Deref, DerefMut}, }; @@ -37,6 +37,24 @@ impl DerefMut for DirectEventContent { } } +impl IntoIterator for DirectEventContent { + type Item = (OwnedUserId, Vec); + type IntoIter = btree_map::IntoIter>; + + fn into_iter(self) -> Self::IntoIter { + self.0.into_iter() + } +} + +impl FromIterator<(OwnedUserId, Vec)> for DirectEventContent { + fn from_iter(iter: T) -> Self + where + T: IntoIterator)>, + { + Self(BTreeMap::from_iter(iter)) + } +} + #[cfg(all(test, feature = "rand"))] mod tests { use std::collections::BTreeMap;