datex_core/values/serde/
error.rs

1use core::fmt;
2use serde::de::Error;
3use serde::ser::StdError;
4use serde::ser::{self};
5use std::fmt::Display;
6use std::io;
7
8// TODO #147: Add deserialization error and wrap compiler error and execution error into it
9
10#[derive(Debug)]
11pub struct SerializationError(pub String);
12impl ser::Error for SerializationError {
13    fn custom<T: fmt::Display>(msg: T) -> Self {
14        SerializationError(msg.to_string())
15    }
16}
17impl Error for SerializationError {
18    fn custom<T: fmt::Display>(msg: T) -> Self {
19        SerializationError(msg.to_string())
20    }
21}
22
23impl From<io::Error> for SerializationError {
24    fn from(e: io::Error) -> Self {
25        SerializationError(e.to_string())
26    }
27}
28impl StdError for SerializationError {}
29impl Display for SerializationError {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        write!(f, "SerializationError: {}", self.0)
32    }
33}