From ad86f4603ab17955b3f2a284c6c0e60273bbaec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Mon, 6 Feb 2023 17:33:00 +0100 Subject: [PATCH] events: Derive Hash for ReceiptType and ReceiptThread Since uniqueness of receipts is determined per type and per thread it's common to use them as keys of a map. --- crates/ruma-common/CHANGELOG.md | 4 ++++ crates/ruma-common/src/events/receipt.rs | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/ruma-common/CHANGELOG.md b/crates/ruma-common/CHANGELOG.md index bf16ac7d..2eddf170 100644 --- a/crates/ruma-common/CHANGELOG.md +++ b/crates/ruma-common/CHANGELOG.md @@ -1,5 +1,9 @@ # [unreleased] +Improvements: + +- Derive `Hash` for `ReceiptType` and `ReceiptThread` + # 0.11.1 Improvements: diff --git a/crates/ruma-common/src/events/receipt.rs b/crates/ruma-common/src/events/receipt.rs index ea1f3644..05226f20 100644 --- a/crates/ruma-common/src/events/receipt.rs +++ b/crates/ruma-common/src/events/receipt.rs @@ -59,7 +59,7 @@ pub type Receipts = BTreeMap; /// The type of receipt. #[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))] -#[derive(Clone, PartialOrdAsRefStr, OrdAsRefStr, PartialEqAsRefStr, Eq, StringEnum)] +#[derive(Clone, PartialOrdAsRefStr, OrdAsRefStr, PartialEqAsRefStr, Eq, StringEnum, Hash)] #[non_exhaustive] pub enum ReceiptType { /// A [public read receipt]. @@ -132,7 +132,7 @@ impl Receipt { /// representation, obtained through [`.as_str()`](Self::as_str()). /// /// [thread a receipt applies to]: https://spec.matrix.org/v1.4/client-server-api/#threaded-read-receipts -#[derive(Clone, Debug, Default, PartialEq, Eq)] +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum ReceiptThread { /// The receipt applies to the timeline, regardless of threads.