use std::fmt;
#[derive(Debug)]
pub enum Error {
Cuda(String),
NoCuda,
Io(std::io::Error),
Checkpoint(String),
Dataset(String),
Shape(String),
}
pub type Result<T> = std::result::Result<T, Error>;
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Cuda(msg) => write!(f, "cuda: {msg}"),
Error::NoCuda => write!(
f,
"cuda: no device available (build with the `cuda` feature and a working GPU)"
),
Error::Io(e) => write!(f, "io: {e}"),
Error::Checkpoint(msg) => write!(f, "checkpoint: {msg}"),
Error::Dataset(msg) => write!(f, "dataset: {msg}"),
Error::Shape(msg) => write!(f, "shape: {msg}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Io(e) => Some(e),
_ => None,
}
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Error::Io(e)
}
}