summaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs
new file mode 100644
index 0000000..b06d023
--- /dev/null
+++ b/src/error.rs
@@ -0,0 +1,35 @@
+use data_encoding;
+use serde::de;
+
+use std::fmt::Display;
+use std::io;
+use std::string;
+
+error_chain! {
+ errors {
+ Custom(msg: String)
+ Unsupported
+ }
+
+ foreign_links {
+ Decoding(data_encoding::decode::Error);
+ Io(io::Error);
+ Utf8(string::FromUtf8Error);
+ }
+}
+
+impl Error {
+ /// Generate error to show top-level type cannot be deserialized.
+ pub fn top_level(object: &'static str) -> Error {
+ ErrorKind::Custom(format!("cannot deserialize {} at the top level.\
+ Try deserializing into a struct.", object)).into()
+
+ }
+}
+
+impl de::Error for Error {
+ fn custom<T>(msg: T) -> Self
+ where T: Display {
+ ErrorKind::Custom(msg.to_string()).into()
+ }
+} \ No newline at end of file