use std::error::Error;
use std::fmt;
#[derive(Debug, Clone, PartialEq)]
pub enum SnowIDError {
InvalidNodeId { node_id: u16, max: u16 },
}
impl fmt::Display for SnowIDError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Self::InvalidNodeId { node_id, max } => {
write!(f, "Node ID {node_id} is invalid. Maximum allowed value is {max}")
},
}
}
}
impl Error for SnowIDError {}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_display() {
let invalid_node = SnowIDError::InvalidNodeId { node_id: 1024, max: 1023 };
assert_eq!(invalid_node.to_string(), "Node ID 1024 is invalid. Maximum allowed value is 1023");
}
#[test]
fn test_error_debug() {
let invalid_node = SnowIDError::InvalidNodeId { node_id: 1024, max: 1023 };
assert!(format!("{invalid_node:?}").contains("InvalidNodeId"));
}
#[test]
fn test_error_clone() {
let original = SnowIDError::InvalidNodeId { node_id: 1024, max: 1023 };
let cloned = original.clone();
assert_eq!(original, cloned);
}
}