1 use super::{Custom, Error, ErrorKind, Repr};
4 use crate::mem::size_of;
5 use crate::sys::decode_error_kind;
6 use crate::sys::os::error_string;
10 assert!(size_of::<Error>() <= size_of::<[usize; 2]>());
14 fn test_debug_error() {
16 let msg = error_string(code);
17 let kind = decode_error_kind(code);
19 repr: Repr::Custom(box Custom {
20 kind: ErrorKind::InvalidInput,
21 error: box Error { repr: super::Repr::Os(code) },
24 let expected = format!(
35 assert_eq!(format!("{:?}", err), expected);
39 fn test_downcasting() {
43 impl fmt::Display for TestError {
44 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49 impl error::Error for TestError {}
51 // we have to call all of these UFCS style right now since method
52 // resolution won't implicitly drop the Send+Sync bounds
53 let mut err = Error::new(ErrorKind::Other, TestError);
54 assert!(err.get_ref().unwrap().is::<TestError>());
55 assert_eq!("asdf", err.get_ref().unwrap().to_string());
56 assert!(err.get_mut().unwrap().is::<TestError>());
57 let extracted = err.into_inner().unwrap();
58 extracted.downcast::<TestError>().unwrap();
63 const E: Error = Error::new_const(ErrorKind::NotFound, &"hello");
65 assert_eq!(E.kind(), ErrorKind::NotFound);
66 assert_eq!(E.to_string(), "hello");
67 assert!(format!("{:?}", E).contains("\"hello\""));
68 assert!(format!("{:?}", E).contains("NotFound"));