diff options
Diffstat (limited to 'askama_shared/src/error.rs')
-rw-r--r-- | askama_shared/src/error.rs | 16 |
1 files changed, 15 insertions, 1 deletions
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; |