lowlevel_types/ascii/
error.rs1use std::{error::Error, fmt::Display};
2
3#[derive(Debug, PartialEq)]
5pub struct ASCIIError {
6 pub message: String,
8}
9
10impl Display for ASCIIError {
11 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12 write!(f, "{}", self.message)
13 }
14}
15
16impl Error for ASCIIError {
17 fn source(&self) -> Option<&(dyn Error + 'static)> {
18 None
19 }
20
21 fn description(&self) -> &str {
22 "description() is deprecated; use Display"
23 }
24
25 fn cause(&self) -> Option<&dyn Error> {
26 self.source()
27 }
28}
29
30#[cfg(test)]
31mod tests {
32 use std::error::Error;
33
34 use crate::ascii::ASCIIError;
35
36 #[test]
37 #[allow(deprecated)]
38 fn test() {
39 let e = ASCIIError {
40 message: String::from("test"),
41 };
42 assert_eq!(format!("{}", e), "test");
43 assert!(e.source().is_none());
44 assert!(e.cause().is_none());
45 assert_eq!(e.description(), "description() is deprecated; use Display");
46 }
47}