From 519ab3ff0af402c1f0f4d75ed1aac3cf88cc31f7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 17 May 2020 18:50:32 +0200 Subject: [PATCH] Implement Display for r0::keys::AlgorithmAndDeviceId --- CHANGELOG.md | 4 ++++ src/r0/keys.rs | 13 +++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2961d37..923414b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ Breaking changes: * The `event_id` in the response for the message and state sending endpoints is now required * r0.6.0 doesn't say they are required, but this has been fixed for the next version of the spec +Improvements: + +* `r0::keys::AlgorithmAndDeviceId` now implements `Display` + # 0.8.0 Breaking changes: diff --git a/src/r0/keys.rs b/src/r0/keys.rs index 73f3eb25..21a40267 100644 --- a/src/r0/keys.rs +++ b/src/r0/keys.rs @@ -3,7 +3,7 @@ use std::{ collections::BTreeMap, convert::TryFrom, - fmt::{Debug, Display, Error as FmtError, Formatter}, + fmt::{self, Debug, Display, Formatter}, }; use ruma_events::Algorithm; @@ -35,7 +35,7 @@ pub enum KeyAlgorithm { } impl Display for KeyAlgorithm { - fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { let algorithm_str = match *self { KeyAlgorithm::Ed25519 => "ed25519", KeyAlgorithm::Curve25519 => "curve25519", @@ -62,13 +62,18 @@ impl TryFrom<&'_ str> for KeyAlgorithm { #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct AlgorithmAndDeviceId(pub KeyAlgorithm, pub DeviceId); +impl Display for AlgorithmAndDeviceId { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + write!(f, "{}:{}", self.0, self.1) + } +} + impl Serialize for AlgorithmAndDeviceId { fn serialize(&self, serializer: S) -> Result where S: Serializer, { - let s = format!("{}:{}", self.0, self.1); - serializer.serialize_str(&s) + serializer.serialize_str(&self.to_string()) } }