aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared/src/error.rs
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2019-01-17 11:30:13 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2019-01-17 17:24:23 +0100
commita1b5a9ee2e3ce42c4c5bd52adda2879e902540c6 (patch)
tree7e59c480edbef1f5b8868e02c3fcfd6530b08bb9 /askama_shared/src/error.rs
parent744127bd1cf8897961f978f088bb2c9ee996362a (diff)
downloadaskama-a1b5a9ee2e3ce42c4c5bd52adda2879e902540c6.tar.gz
askama-a1b5a9ee2e3ce42c4c5bd52adda2879e902540c6.tar.bz2
askama-a1b5a9ee2e3ce42c4c5bd52adda2879e902540c6.zip
Add optional support for yaml filter (see #192)
Diffstat (limited to '')
-rw-r--r--askama_shared/src/error.rs16
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;