From 9cb9b1104a67101160541868244d6a3eb236452c Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 15 Sep 2021 18:15:01 +0200 Subject: [PATCH] state-res: Remove unused Event trait methods --- .../ruma-state-res/benches/state_res_bench.rs | 47 +--------------- crates/ruma-state-res/src/state_event.rs | 55 +------------------ crates/ruma-state-res/src/test_utils.rs | 48 +--------------- 3 files changed, 7 insertions(+), 143 deletions(-) diff --git a/crates/ruma-state-res/benches/state_res_bench.rs b/crates/ruma-state-res/benches/state_res_bench.rs index 87ea416e..19fb723c 100644 --- a/crates/ruma-state-res/benches/state_res_bench.rs +++ b/crates/ruma-state-res/benches/state_res_bench.rs @@ -528,18 +528,11 @@ fn BAN_STATE_SET() -> HashMap> { } mod event { - use std::collections::BTreeMap; - - use js_int::UInt; use ruma_common::MilliSecondsSinceUnixEpoch; - use ruma_events::{ - pdu::{EventHash, Pdu}, - EventType, - }; - use ruma_identifiers::{EventId, RoomId, ServerName, ServerSigningKeyId, UserId}; + use ruma_events::{pdu::Pdu, EventType}; + use ruma_identifiers::{EventId, RoomId, UserId}; use ruma_state_res::Event; use serde::{Deserialize, Serialize}; - use serde_json::Value as JsonValue; impl Event for StateEvent { fn event_id(&self) -> &EventId { @@ -609,15 +602,6 @@ mod event { } } - fn depth(&self) -> &UInt { - match &self.rest { - Pdu::RoomV1Pdu(ev) => &ev.depth, - Pdu::RoomV3Pdu(ev) => &ev.depth, - #[cfg(not(feature = "unstable-exhaustive-types"))] - _ => unreachable!("new PDU version"), - } - } - fn auth_events(&self) -> Box + '_> { match &self.rest { Pdu::RoomV1Pdu(ev) => Box::new(ev.auth_events.iter().map(|(id, _)| id)), @@ -635,33 +619,6 @@ mod event { _ => unreachable!("new PDU version"), } } - - fn hashes(&self) -> &EventHash { - match &self.rest { - Pdu::RoomV1Pdu(ev) => &ev.hashes, - Pdu::RoomV3Pdu(ev) => &ev.hashes, - #[cfg(not(feature = "unstable-exhaustive-types"))] - _ => unreachable!("new PDU version"), - } - } - - fn signatures(&self) -> BTreeMap, BTreeMap> { - match &self.rest { - Pdu::RoomV1Pdu(_) => maplit::btreemap! {}, - Pdu::RoomV3Pdu(ev) => ev.signatures.clone(), - #[cfg(not(feature = "unstable-exhaustive-types"))] - _ => unreachable!("new PDU version"), - } - } - - fn unsigned(&self) -> &BTreeMap { - match &self.rest { - Pdu::RoomV1Pdu(ev) => &ev.unsigned, - Pdu::RoomV3Pdu(ev) => &ev.unsigned, - #[cfg(not(feature = "unstable-exhaustive-types"))] - _ => unreachable!("new PDU version"), - } - } } #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/crates/ruma-state-res/src/state_event.rs b/crates/ruma-state-res/src/state_event.rs index 3689c3f4..73933bb0 100644 --- a/crates/ruma-state-res/src/state_event.rs +++ b/crates/ruma-state-res/src/state_event.rs @@ -1,10 +1,8 @@ -use std::{collections::BTreeMap, sync::Arc}; +use std::sync::Arc; -use js_int::UInt; use ruma_common::MilliSecondsSinceUnixEpoch; -use ruma_events::{pdu::EventHash, EventType}; -use ruma_identifiers::{EventId, RoomId, ServerName, ServerSigningKeyId, UserId}; -use serde_json::value::Value as JsonValue; +use ruma_events::EventType; +use ruma_identifiers::{EventId, RoomId, UserId}; /// Abstraction of a PDU so users can have their own PDU types. pub trait Event { @@ -37,27 +35,12 @@ pub trait Event { // Requires GATs to avoid boxing (and TAIT for making it convenient). fn prev_events(&self) -> Box + '_>; - /// The maximum number of `prev_events` plus 1. - /// - /// This is only used in state resolution version 1. - fn depth(&self) -> &UInt; - /// All the authenticating events for this event. // Requires GATs to avoid boxing (and TAIT for making it convenient). fn auth_events(&self) -> Box + '_>; /// If this event is a redaction event this is the event it redacts. fn redacts(&self) -> Option<&EventId>; - - /// The `unsigned` content of this event. - fn unsigned(&self) -> &BTreeMap; - - /// The content hash of this PDU. - fn hashes(&self) -> &EventHash; - - /// A map of server names to another map consisting of the signing key id and finally the - /// signature. - fn signatures(&self) -> BTreeMap, BTreeMap>; } impl Event for &T { @@ -93,10 +76,6 @@ impl Event for &T { (*self).prev_events() } - fn depth(&self) -> &UInt { - (*self).depth() - } - fn auth_events(&self) -> Box + '_> { (*self).auth_events() } @@ -104,18 +83,6 @@ impl Event for &T { fn redacts(&self) -> Option<&EventId> { (*self).redacts() } - - fn unsigned(&self) -> &BTreeMap { - (*self).unsigned() - } - - fn hashes(&self) -> &EventHash { - (*self).hashes() - } - - fn signatures(&self) -> BTreeMap, BTreeMap> { - (*self).signatures() - } } impl Event for Arc { @@ -151,10 +118,6 @@ impl Event for Arc { (&**self).prev_events() } - fn depth(&self) -> &UInt { - (&**self).depth() - } - fn auth_events(&self) -> Box + '_> { (&**self).auth_events() } @@ -162,16 +125,4 @@ impl Event for Arc { fn redacts(&self) -> Option<&EventId> { (&**self).redacts() } - - fn unsigned(&self) -> &BTreeMap { - (&**self).unsigned() - } - - fn hashes(&self) -> &EventHash { - (&**self).hashes() - } - - fn signatures(&self) -> BTreeMap, BTreeMap> { - (&**self).signatures() - } } diff --git a/crates/ruma-state-res/src/test_utils.rs b/crates/ruma-state-res/src/test_utils.rs index de470e4f..1646c3e9 100644 --- a/crates/ruma-state-res/src/test_utils.rs +++ b/crates/ruma-state-res/src/test_utils.rs @@ -528,18 +528,10 @@ pub fn INITIAL_EDGES() -> Vec { } pub mod event { - use std::collections::BTreeMap; - - use js_int::UInt; - use ruma_events::{ - exports::ruma_common::MilliSecondsSinceUnixEpoch, - pdu::{EventHash, Pdu}, - EventType, - }; - use ruma_identifiers::{EventId, RoomId, ServerName, ServerSigningKeyId, UserId}; + use ruma_events::{exports::ruma_common::MilliSecondsSinceUnixEpoch, pdu::Pdu, EventType}; + use ruma_identifiers::{EventId, RoomId, UserId}; use serde::{Deserialize, Serialize}; - use serde_json::Value as JsonValue; use crate::Event; @@ -611,15 +603,6 @@ pub mod event { } } - fn depth(&self) -> &UInt { - match &self.rest { - Pdu::RoomV1Pdu(ev) => &ev.depth, - Pdu::RoomV3Pdu(ev) => &ev.depth, - #[cfg(not(feature = "unstable-exhaustive-types"))] - _ => unreachable!("new PDU version"), - } - } - fn auth_events(&self) -> Box + '_> { match &self.rest { Pdu::RoomV1Pdu(ev) => Box::new(ev.auth_events.iter().map(|(id, _)| id)), @@ -637,33 +620,6 @@ pub mod event { _ => unreachable!("new PDU version"), } } - - fn hashes(&self) -> &EventHash { - match &self.rest { - Pdu::RoomV1Pdu(ev) => &ev.hashes, - Pdu::RoomV3Pdu(ev) => &ev.hashes, - #[cfg(not(feature = "unstable-exhaustive-types"))] - _ => unreachable!("new PDU version"), - } - } - - fn signatures(&self) -> BTreeMap, BTreeMap> { - match &self.rest { - Pdu::RoomV1Pdu(_) => BTreeMap::new(), - Pdu::RoomV3Pdu(ev) => ev.signatures.clone(), - #[cfg(not(feature = "unstable-exhaustive-types"))] - _ => unreachable!("new PDU version"), - } - } - - fn unsigned(&self) -> &BTreeMap { - match &self.rest { - Pdu::RoomV1Pdu(ev) => &ev.unsigned, - Pdu::RoomV3Pdu(ev) => &ev.unsigned, - #[cfg(not(feature = "unstable-exhaustive-types"))] - _ => unreachable!("new PDU version"), - } - } } #[derive(Clone, Debug, Deserialize, Serialize)]