From 5e7f60e5d9229b2d22f5cb51ad943a58e72dd60a Mon Sep 17 00:00:00 2001 From: Devin Ragotzy Date: Sun, 1 Nov 2020 18:52:50 -0500 Subject: [PATCH] Add gen-eventid feature to generate EventId every deserialize So we do not rely on any found EventId, this makes all the tests break. --- Cargo.toml | 1 + src/state_event.rs | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8623837b..2c44e313 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,7 @@ features = ["client-api", "federation-api", "appservice-api", "unstable-pre-spec [features] default = ["unstable-pre-spec"] +gen-eventid = [] unstable-pre-spec = ["ruma/unstable-pre-spec"] [dev-dependencies] diff --git a/src/state_event.rs b/src/state_event.rs index afa1ba3c..330143d8 100644 --- a/src/state_event.rs +++ b/src/state_event.rs @@ -92,18 +92,18 @@ impl<'de> de::Deserialize<'de> for StateEvent { } } -// #[cfg(not(test))] -// fn event_id(json: &RawJsonValue) -> Result { -// use std::convert::TryFrom; -// EventId::try_from(format!( -// "${}", -// reference_hash(&from_raw_json_value(&json)?, &RoomVersionId::Version6) -// .map_err(de::Error::custom)?, -// )) -// .map_err(de::Error::custom) -// } +#[cfg(feature = "gen-eventid")] +fn event_id(json: &RawJsonValue) -> Result { + use std::convert::TryFrom; + EventId::try_from(format!( + "${}", + reference_hash(&from_raw_json_value(&json)?, &RoomVersionId::Version6) + .map_err(de::Error::custom)?, + )) + .map_err(de::Error::custom) +} -// #[cfg(test)] +#[cfg(not(feature = "gen-eventid"))] fn event_id(json: &RawJsonValue) -> Result { use std::convert::TryFrom; Ok(match from_raw_json_value::(&json) {