1#[cfg(feature = "try_from")]
4pub use self::try_from::TryFromReprError;
5#[cfg(feature = "try_into")]
6pub use self::try_into::TryIntoError;
7
8#[cfg(feature = "try_from")]
9mod try_from {
10 use core::{error::Error, fmt};
11
12 #[derive(Clone, Copy, Debug)]
17 pub struct TryFromReprError<T> {
18 pub input: T,
23 }
24
25 impl<T> TryFromReprError<T> {
26 #[doc(hidden)]
27 #[must_use]
28 #[inline]
29 pub const fn new(input: T) -> Self {
30 Self { input }
31 }
32 }
33
34 impl<T: fmt::Debug> fmt::Display for TryFromReprError<T> {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 write!(
38 f,
39 "`{:?}` does not correspond to a unit variant",
40 self.input
41 )
42 }
43 }
44
45 impl<T: fmt::Debug> Error for TryFromReprError<T> {}
47}
48
49#[cfg(feature = "try_into")]
50mod try_into {
51 use core::{error::Error, fmt};
52
53 #[derive(Clone, Copy, Debug)]
57 pub struct TryIntoError<T> {
58 pub input: T,
63 variant_names: &'static str,
64 output_type: &'static str,
65 }
66
67 impl<T> TryIntoError<T> {
68 #[doc(hidden)]
69 #[must_use]
70 #[inline]
71 pub const fn new(
72 input: T,
73 variant_names: &'static str,
74 output_type: &'static str,
75 ) -> Self {
76 Self {
77 input,
78 variant_names,
79 output_type,
80 }
81 }
82 }
83
84 impl<T> fmt::Display for TryIntoError<T> {
85 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
86 write!(
87 f,
88 "Only {} can be converted to {}",
89 self.variant_names, self.output_type,
90 )
91 }
92 }
93
94 impl<T: fmt::Debug> Error for TryIntoError<T> {}
95}