• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use std::io;
2 use thiserror::Error;
3 
4 #[derive(Error, Debug)]
5 #[error("...")]
6 pub struct ErrorStruct {
7     #[from]
8     source: io::Error,
9 }
10 
11 #[derive(Error, Debug)]
12 #[error("...")]
13 pub struct ErrorStructOptional {
14     #[from]
15     source: Option<io::Error>,
16 }
17 
18 #[derive(Error, Debug)]
19 #[error("...")]
20 pub struct ErrorTuple(#[from] io::Error);
21 
22 #[derive(Error, Debug)]
23 #[error("...")]
24 pub struct ErrorTupleOptional(#[from] Option<io::Error>);
25 
26 #[derive(Error, Debug)]
27 #[error("...")]
28 pub enum ErrorEnum {
29     Test {
30         #[from]
31         source: io::Error,
32     },
33 }
34 
35 #[derive(Error, Debug)]
36 #[error("...")]
37 pub enum ErrorEnumOptional {
38     Test {
39         #[from]
40         source: Option<io::Error>,
41     },
42 }
43 
44 #[derive(Error, Debug)]
45 #[error("...")]
46 pub enum Many {
47     Any(#[from] anyhow::Error),
48     Io(#[from] io::Error),
49 }
50 
assert_impl<T: From<io::Error>>()51 fn assert_impl<T: From<io::Error>>() {}
52 
53 #[test]
test_from()54 fn test_from() {
55     assert_impl::<ErrorStruct>();
56     assert_impl::<ErrorStructOptional>();
57     assert_impl::<ErrorTuple>();
58     assert_impl::<ErrorTupleOptional>();
59     assert_impl::<ErrorEnum>();
60     assert_impl::<ErrorEnumOptional>();
61     assert_impl::<Many>();
62 }
63