1 use super::{Custom, Error, ErrorKind, Repr}
;
4 use crate::sys
::decode_error_kind
;
5 use crate::sys
::os
::error_string
;
8 fn test_debug_error() {
10 let msg
= error_string(code
);
11 let kind
= decode_error_kind(code
);
13 repr
: Repr
::Custom(box Custom
{
14 kind
: ErrorKind
::InvalidInput
,
15 error
: box Error { repr: super::Repr::Os(code) }
,
18 let expected
= format
!(
29 assert_eq
!(format
!("{:?}", err
), expected
);
33 fn test_downcasting() {
37 impl fmt
::Display
for TestError
{
38 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
43 impl error
::Error
for TestError {}
45 // we have to call all of these UFCS style right now since method
46 // resolution won't implicitly drop the Send+Sync bounds
47 let mut err
= Error
::new(ErrorKind
::Other
, TestError
);
48 assert
!(err
.get_ref().unwrap().is
::<TestError
>());
49 assert_eq
!("asdf", err
.get_ref().unwrap().to_string());
50 assert
!(err
.get_mut().unwrap().is
::<TestError
>());
51 let extracted
= err
.into_inner().unwrap();
52 extracted
.downcast
::<TestError
>().unwrap();