From 810bf56874b31750d8cec3550e1fd181346ab382 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 18 Feb 2020 20:58:29 +0100 Subject: [PATCH] Add strum::ParseError variant to DeserializationError --- Cargo.toml | 1 + ruma-api-macros/src/api/request.rs | 6 +----- src/error.rs | 11 +++++++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ac18a4a8..054a1913 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ ruma-identifiers = { version = "0.14.1", optional = true } serde = { version = "1.0.104", features = ["derive"], optional = true } serde_json = "1.0.47" serde_urlencoded = "0.6.1" +strum = "0.17.1" url = { version = "2.1.1", optional = true } [dev-dependencies] diff --git a/ruma-api-macros/src/api/request.rs b/ruma-api-macros/src/api/request.rs index cb5e57f0..ed14f42c 100644 --- a/ruma-api-macros/src/api/request.rs +++ b/ruma-api-macros/src/api/request.rs @@ -353,11 +353,7 @@ impl ToTokens for Request { quote! { /// Data in the request path. - #[derive( - Debug, - ruma_api::exports::serde::Deserialize, - ruma_api::exports::serde::Serialize, - )] + #[derive(Debug)] struct RequestPath { #(#fields),* } diff --git a/src/error.rs b/src/error.rs index f90f37f8..1047c58a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -194,6 +194,9 @@ pub enum DeserializationError { Json(serde_json::Error), Query(serde_urlencoded::de::Error), Ident(ruma_identifiers::Error), + // String <> Enum conversion failed. This can currently only happen in path + // segment deserialization + Strum(strum::ParseError), } impl Display for DeserializationError { @@ -202,6 +205,7 @@ impl Display for DeserializationError { DeserializationError::Json(err) => Display::fmt(err, f), DeserializationError::Query(err) => Display::fmt(err, f), DeserializationError::Ident(err) => Display::fmt(err, f), + DeserializationError::Strum(err) => Display::fmt(err, f), } } } @@ -227,6 +231,13 @@ impl From for DeserializationError { } } +#[doc(hidden)] +impl From for DeserializationError { + fn from(err: strum::ParseError) -> Self { + Self::Strum(err) + } +} + #[doc(hidden)] impl From for DeserializationError { fn from(err: std::convert::Infallible) -> Self {