use std::{ error, fmt, }; #[derive(Debug)] pub enum Error { RNG, Format(fmt::Error), Unknown, } impl error::Error for Error { fn source(&self) -> Option<&(dyn error::Error + 'static)> { match &self { Self::Format(rng) => Some(rng), _ => None, } } } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "temp file error: ")?; match self { Error::RNG => write!(f, "rng failed"), Error::Format(fmt) => write!(f, "formatting: {}", fmt), _ => write!(f, "unknown"), } } } impl From for Error { fn from(f: fmt::Error) -> Self { Self::Format(f) } } impl From for Error { fn from(_f: getrandom::Error) -> Self { Self::RNG } }