use std::fmt;
pub const EXIT_USAGE: u8 = 1;
pub const EXIT_NOT_FOR_US: u8 = 2;
pub const EXIT_AUTH: u8 = 3;
#[derive(Debug)]
pub struct Failure {
pub code: u8,
pub message: String,
}
impl Failure {
pub fn new(code: u8, message: impl Into<String>) -> Self {
Self {
code,
message: message.into(),
}
}
pub fn usage(message: impl Into<String>) -> Self {
Self::new(EXIT_USAGE, message)
}
}
impl fmt::Display for Failure {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.message)
}
}
impl From<std::io::Error> for Failure {
fn from(err: std::io::Error) -> Self {
Self::usage(format!("io error: {err}"))
}
}
pub type Result<T> = std::result::Result<T, Failure>;