use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FunctionKind {
Normal,
InterruptHandler,
}
impl FunctionKind {
#[must_use]
pub const fn is_interrupt_handler(self) -> bool {
matches!(self, Self::InterruptHandler)
}
#[must_use]
pub const fn is_normal(self) -> bool {
matches!(self, Self::Normal)
}
}
impl fmt::Display for FunctionKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Normal => write!(f, "normal"),
Self::InterruptHandler => write!(f, "interrupt_handler"),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_kind_is_normal() {
assert!(FunctionKind::Normal.is_normal());
assert!(!FunctionKind::Normal.is_interrupt_handler());
}
#[test]
fn interrupt_handler_classification() {
assert!(FunctionKind::InterruptHandler.is_interrupt_handler());
assert!(!FunctionKind::InterruptHandler.is_normal());
}
#[test]
fn display_normal() {
assert_eq!(FunctionKind::Normal.to_string(), "normal");
}
#[test]
fn display_interrupt_handler() {
assert_eq!(
FunctionKind::InterruptHandler.to_string(),
"interrupt_handler"
);
}
#[test]
fn kind_is_copy_and_eq() {
assert_eq!(FunctionKind::Normal, FunctionKind::Normal);
assert_eq!(
FunctionKind::InterruptHandler,
FunctionKind::InterruptHandler
);
assert_ne!(FunctionKind::Normal, FunctionKind::InterruptHandler);
}
}