use std::fmt::Display;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Subject {
Account,
Order,
Job,
EabCredential,
Operator,
Session,
Profile,
}
impl Subject {
#[must_use]
pub fn missing(self, id: impl Display) -> String {
let noun = match self {
Self::Account => "account",
Self::Order => "order",
Self::Job => "job",
Self::EabCredential => "EAB credential",
Self::Operator => "operator",
Self::Session => "session",
Self::Profile => return format!("no profile named `{id}` is mounted"),
};
format!("no such {noun}: {id}")
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn each_subject_names_itself_and_the_id() {
assert_eq!(Subject::Account.missing("a-1"), "no such account: a-1");
assert_eq!(
Subject::EabCredential.missing("kid-9"),
"no such EAB credential: kid-9"
);
assert_eq!(
Subject::Profile.missing("le"),
"no profile named `le` is mounted"
);
}
}