You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
797 B
52 lines
797 B
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<fmt::Error> for Error
|
|
{
|
|
fn from(f: fmt::Error) -> Self
|
|
{
|
|
Self::Format(f)
|
|
}
|
|
}
|
|
impl From<getrandom::Error> for Error
|
|
{
|
|
fn from(_f: getrandom::Error) -> Self
|
|
{
|
|
Self::RNG
|
|
}
|
|
}
|