From d4a196f682ce75a33acae1950a6b4530b5a9ac4f Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 9 Jun 2020 01:33:40 +0200 Subject: [PATCH] Update ReceiptEventContent representation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … and implement Deref, DerefMut for it --- src/receipt.rs | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/receipt.rs b/src/receipt.rs index 65617d27..61f580a3 100644 --- a/src/receipt.rs +++ b/src/receipt.rs @@ -1,21 +1,35 @@ //! Types for the *m.receipt* event. -use std::{collections::BTreeMap, time::SystemTime}; +use std::{ + collections::BTreeMap, + ops::{Deref, DerefMut}, + time::SystemTime, +}; use ruma_events_macros::EphemeralRoomEventContent; use ruma_identifiers::{EventId, UserId}; use serde::{Deserialize, Serialize}; -/// Informs the client who has read a message specified by it's event id. +/// The payload for `ReceiptEvent`. +/// +/// A mapping of event ID to a collection of receipts for this event ID. The event ID is the ID of +/// the event being acknowledged and *not* an ID for the receipt itself. #[derive(Clone, Debug, Deserialize, Serialize, EphemeralRoomEventContent)] #[ruma_event(type = "m.receipt")] -#[serde(transparent)] -pub struct ReceiptEventContent { - /// The payload for `ReceiptEvent`. - /// - /// A mapping of event ID to a collection of receipts for this event ID. The event ID is the ID of - /// the event being acknowledged and *not* an ID for the receipt itself. - pub receipts: BTreeMap, +pub struct ReceiptEventContent(pub BTreeMap); + +impl Deref for ReceiptEventContent { + type Target = BTreeMap; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for ReceiptEventContent { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } } /// A collection of receipts.