From a1b5a9ee2e3ce42c4c5bd52adda2879e902540c6 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 17 Jan 2019 11:30:13 +0100 Subject: Add optional support for yaml filter (see #192) --- askama_shared/src/error.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'askama_shared/src/error.rs') diff --git a/askama_shared/src/error.rs b/askama_shared/src/error.rs index bd35126..f3e8b48 100644 --- a/askama_shared/src/error.rs +++ b/askama_shared/src/error.rs @@ -32,6 +32,10 @@ pub enum Error { #[cfg(feature = "serde_json")] Json(::serde_json::Error), + /// yaml conversion error + #[cfg(feature = "serde_yaml")] + Yaml(::serde_yaml::Error), + /// This error needs to be non-exhaustive as /// the `Json` variants existence depends on /// a feature. @@ -54,6 +58,8 @@ impl ErrorTrait for Error { Error::Fmt(ref err) => err.source(), #[cfg(feature = "serde_json")] Error::Json(ref err) => err.source(), + #[cfg(feature = "serde_yaml")] + Error::Yaml(ref err) => err.source(), _ => None, } } @@ -63,9 +69,10 @@ impl Display for Error { fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { Error::Fmt(ref err) => write!(formatter, "formatting error: {}", err), - #[cfg(feature = "serde_json")] Error::Json(ref err) => write!(formatter, "json conversion error: {}", err), + #[cfg(feature = "serde_yaml")] + Error::Yaml(ref err) => write!(formatter, "yaml conversion error: {}", err), _ => write!(formatter, "unknown error: __Nonexhaustive"), } } @@ -84,6 +91,13 @@ impl From<::serde_json::Error> for Error { } } +#[cfg(feature = "serde_yaml")] +impl From<::serde_yaml::Error> for Error { + fn from(err: ::serde_yaml::Error) -> Self { + Error::Yaml(err) + } +} + #[cfg(test)] mod tests { use super::Error; -- cgit