1 #![deny(clippy::all, clippy::pedantic)]
2 
3 use ref_cast::RefCast;
4 use std::fmt::Display;
5 use std::path::{Path, PathBuf};
6 use thiserror::Error;
7 
8 #[derive(Error, Debug)]
9 #[error("failed to read '{file}'")]
10 struct StructPathBuf {
11     file: PathBuf,
12 }
13 
14 #[derive(Error, Debug, RefCast)]
15 #[repr(C)]
16 #[error("failed to read '{file}'")]
17 struct StructPath {
18     file: Path,
19 }
20 
21 #[derive(Error, Debug)]
22 enum EnumPathBuf {
23     #[error("failed to read '{0}'")]
24     Read(PathBuf),
25 }
26 
assert<T: Display>(expected: &str, value: T)27 fn assert<T: Display>(expected: &str, value: T) {
28     assert_eq!(expected, value.to_string());
29 }
30 
31 #[test]
test_display()32 fn test_display() {
33     let path = Path::new("/thiserror");
34     let file = path.to_owned();
35     assert("failed to read '/thiserror'", StructPathBuf { file });
36     let file = path.to_owned();
37     assert("failed to read '/thiserror'", EnumPathBuf::Read(file));
38     assert("failed to read '/thiserror'", StructPath::ref_cast(path));
39 }
40