From 8e9a6ffededb89bc87c6ac5d067d8d4249eabf04 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 18 Feb 2020 21:26:41 +0100 Subject: [PATCH] Update ruma-api to 0.14.0 --- CHANGELOG.md | 1 + Cargo.toml | 3 ++- src/r0/push.rs | 24 ++++++++++++------------ src/r0/receipt/create_receipt.rs | 18 +++++++++--------- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15cb638e..8679fff3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Improvements: Breaking changes: +* Update ruma-api to 0.14.0 * Fix `r0::session::get_login_types` # 0.6.0 diff --git a/Cargo.toml b/Cargo.toml index c5e42a88..5ae8d212 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,9 +15,10 @@ edition = "2018" [dependencies] http = "0.2.0" js_int = { version = "0.1.2", features = ["serde"] } -ruma-api = "0.13.0" +ruma-api = "0.14.0" ruma-events = "0.15.1" ruma-identifiers = "0.14.1" serde = { version = "1.0.104", features = ["derive"] } serde_json = "1.0.47" +strum = { version = "0.17.1", features = ["derive"] } url = { version = "2.1.1", features = ["serde"] } diff --git a/src/r0/push.rs b/src/r0/push.rs index 6796d9ec..d1856ff3 100644 --- a/src/r0/push.rs +++ b/src/r0/push.rs @@ -1,6 +1,9 @@ //! Endpoints for push notifications. -use std::fmt::{Display, Formatter, Result as FmtResult}; +use std::{ + convert::TryFrom, + fmt::{Formatter, Result as FmtResult}, +}; use serde::{ de::{Error as SerdeError, MapAccess, Unexpected, Visitor}, @@ -8,6 +11,7 @@ use serde::{ Deserialize, Deserializer, Serialize, Serializer, }; use serde_json::Value as JsonValue; +use strum::{Display, EnumString}; pub mod delete_pushrule; pub mod get_notifications; @@ -23,8 +27,9 @@ pub mod set_pushrule_actions; pub mod set_pushrule_enabled; /// The kinds of push rules that are available -#[derive(Clone, Copy, Debug, Serialize, Deserialize, Eq, PartialEq, Hash)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize, Display, EnumString)] #[serde(rename_all = "snake_case")] +#[strum(serialize_all = "snake_case")] pub enum RuleKind { /// User-configured rules that override all other kinds Override, @@ -42,16 +47,11 @@ pub enum RuleKind { Content, } -impl Display for RuleKind { - fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { - let s = match self { - RuleKind::Override => "override", - RuleKind::Underride => "underride", - RuleKind::Sender => "sender", - RuleKind::Room => "room", - RuleKind::Content => "content", - }; - write!(f, "{}", s) +impl TryFrom<&'_ str> for RuleKind { + type Error = strum::ParseError; + + fn try_from(s: &str) -> Result { + s.parse() } } diff --git a/src/r0/receipt/create_receipt.rs b/src/r0/receipt/create_receipt.rs index 02915540..d2e75699 100644 --- a/src/r0/receipt/create_receipt.rs +++ b/src/r0/receipt/create_receipt.rs @@ -1,10 +1,10 @@ //! [POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-receipt-receipttype-eventid) -use std::fmt::{Display, Error as FmtError, Formatter}; +use std::convert::TryFrom; use ruma_api::ruma_api; use ruma_identifiers::{EventId, RoomId}; -use serde::{Deserialize, Serialize}; +use strum::{Display, EnumString}; ruma_api! { metadata { @@ -32,17 +32,17 @@ ruma_api! { } /// The type of receipt. -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Display, EnumString)] pub enum ReceiptType { /// m.read - #[serde(rename = "m.read")] + #[strum(serialize = "m.read")] Read, } -impl Display for ReceiptType { - fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { - match *self { - ReceiptType::Read => write!(f, "m.read"), - } +impl TryFrom<&'_ str> for ReceiptType { + type Error = strum::ParseError; + + fn try_from(s: &str) -> Result { + s.parse() } }