preserves/implementations/rust/src/error.rs

31 lines
691 B
Rust

#[derive(Debug)]
pub struct Error {
inner: std::io::Error,
}
impl std::convert::From<Error> for std::io::Error {
fn from(e: Error) -> Self {
e.inner
}
}
impl std::convert::From<std::io::Error> for Error {
fn from(inner: std::io::Error) -> Self {
Error { inner }
}
}
impl serde::ser::Error for Error {
fn custom<T: std::fmt::Display>(msg: T) -> Self {
Error { inner: std::io::Error::new(std::io::ErrorKind::Other, msg.to_string()) }
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
self.inner.fmt(f)
}
}
impl std::error::Error for Error {}