use alloc::string::String;
use core::fmt;
use std::io;
use crate::MANIFEST_DIR;
#[derive(Debug)]
pub struct TomlError {
pub(super) error: toml::de::Error,
}
impl fmt::Display for TomlError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.error.fmt(f)
}
}
impl std::error::Error for TomlError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(&self.error)
}
}
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
NotFoundManifestDir,
InvalidManifest(String),
NotFound,
Io(io::Error),
Toml(TomlError),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::NotFoundManifestDir => {
write!(f, "`{MANIFEST_DIR}` environment variable not found")
}
Error::InvalidManifest(reason) => {
write!(f, "The manifest is invalid because: {reason}")
}
Error::NotFound => {
f.write_str("the crate with the specified name not found in dependencies")
}
Error::Io(e) => write!(f, "an error occurred while to open or to read: {e}"),
Error::Toml(e) => write!(f, "an error occurred while parsing the manifest file: {e}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Io(e) => Some(e),
Error::Toml(e) => Some(e),
_ => None,
}
}
}
impl From<io::Error> for Error {
fn from(e: io::Error) -> Self {
Error::Io(e)
}
}