use std::fmt;
use std::io;
use std::string::FromUtf8Error;
#[derive(Debug)]
pub enum Error {
IO(io::Error),
FileFormat(String),
UnsupportedVersion(String),
MissingName(String),
BadNucleotide(char),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::IO(io) => io.fmt(f),
Error::FileFormat(msg) => write!(f, "{}", msg),
Error::UnsupportedVersion(version) => write!(f, "Unsupported version: {}", version),
Error::MissingName(name) => write!(f, "Missing name: {}", name),
Error::BadNucleotide(nuc) => write!(f, "Bad nucleotide: {}", nuc),
}
}
}
impl std::error::Error for Error {}
impl From<io::Error> for Error {
fn from(io: io::Error) -> Self {
Self::IO(io)
}
}
impl From<FromUtf8Error> for Error {
fn from(utf_error: FromUtf8Error) -> Self {
Self::FileFormat(format!("{}", utf_error))
}
}
pub type Result<T> = std::result::Result<T, Error>;