use core::fmt;
use crate::{Abi, Arch, Endian, Env, Os, SubArch};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
Empty,
UnknownArch(String),
UnknownOs(String),
UnknownEnv(String),
Trailing(Vec<String>),
BadVersion {
component: &'static str,
found: String,
},
SubArchMismatch {
arch: Arch,
sub_arch: SubArch,
},
EndianUnsupported {
arch: Arch,
endian: Endian,
},
EnvMismatch {
os: Os,
env: Env,
},
AbiMismatch {
arch: Arch,
abi: Abi,
},
VersionNotAccepted {
component: &'static str,
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Empty => write!(f, "empty target tuple"),
Error::UnknownArch(found) => {
write!(f, "unknown architecture `{found}`")
}
Error::UnknownOs(found) => write!(f, "unknown operating system `{found}`"),
Error::UnknownEnv(found) => write!(f, "unknown environment `{found}`"),
Error::Trailing(rest) => {
write!(f, "unexpected trailing component")?;
if rest.len() > 1 {
f.write_str("s")?;
}
for (i, part) in rest.iter().enumerate() {
if i == 0 {
write!(f, " `{part}`")?;
} else {
write!(f, ", `{part}`")?;
}
}
Ok(())
}
Error::BadVersion { component, found } => {
write!(f, "`{found}` is not a version for the {component} component")
}
Error::SubArchMismatch { arch, sub_arch } => {
write!(f, "`{}` is not a baseline of `{arch}`", sub_arch.as_str())
}
Error::EndianUnsupported { arch, endian } => {
write!(f, "`{arch}` has no {endian} endian mode")
}
Error::EnvMismatch { os, env } => {
write!(f, "`{os}` has no `{env}` environment")
}
Error::AbiMismatch { arch, abi } => {
write!(f, "`{arch}` has one calling convention and cannot select `{abi}`")
}
Error::VersionNotAccepted { component } => {
write!(f, "the {component} component does not take a version")
}
}
}
}
impl std::error::Error for Error {}