appservice: Implement useful traits for ReceiptContent

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

View File

@ -9,6 +9,11 @@ pub mod v1 {
#[cfg(any(feature = "unstable-msc2409", feature = "unstable-msc3202"))]
use std::collections::BTreeMap;
#[cfg(feature = "unstable-msc2409")]
use std::{
collections::btree_map,
ops::{Deref, DerefMut},
};
#[cfg(any(feature = "unstable-msc2409", feature = "unstable-msc3202"))]
use js_int::UInt;
@ -285,6 +290,42 @@ pub mod v1 {
}
}
#[cfg(feature = "unstable-msc2409")]
impl Deref for ReceiptContent {
type Target = BTreeMap<OwnedRoomId, ReceiptMap>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[cfg(feature = "unstable-msc2409")]
impl DerefMut for ReceiptContent {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
#[cfg(feature = "unstable-msc2409")]
impl IntoIterator for ReceiptContent {
type Item = (OwnedRoomId, ReceiptMap);
type IntoIter = btree_map::IntoIter<OwnedRoomId, ReceiptMap>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
#[cfg(feature = "unstable-msc2409")]
impl FromIterator<(OwnedRoomId, ReceiptMap)> for ReceiptContent {
fn from_iter<T>(iter: T) -> Self
where
T: IntoIterator<Item = (OwnedRoomId, ReceiptMap)>,
{
Self(BTreeMap::from_iter(iter))
}
}
/// Mapping between user and `ReceiptData`.
#[cfg(feature = "unstable-msc2409")]
#[derive(Clone, Debug, Deserialize, Serialize)]