use std::fmt;
#[derive(Debug, Copy, Clone)]
pub struct DecodeLengthError {
pub num_chars: usize,
pub expected_num_chars: usize,
}
impl std::error::Error for DecodeLengthError {}
impl fmt::Display for DecodeLengthError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"Passed {} - expected {} characters",
self.num_chars, self.expected_num_chars,
)
}
}
#[cfg(test)]
mod tests {
use super::DecodeLengthError;
#[test]
fn validate_decode_length_error_text() {
let error = DecodeLengthError {
num_chars: 10,
expected_num_chars: 29,
};
assert_eq!(error.to_string(), "Passed 10 - expected 29 characters");
}
}