1 use crate::std::fmt;
2 
3 /// The error that can occur when creating a [`Uuid`].
4 ///
5 /// [`Uuid`]: struct.Uuid.html
6 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
7 pub(crate) struct Error {
8     expected: usize,
9     found: usize,
10 }
11 
12 impl Error {
13     /// The expected number of bytes.
14     #[inline]
expected(&self) -> usize15     const fn expected(&self) -> usize {
16         self.expected
17     }
18 
19     /// The number of bytes found.
20     #[inline]
found(&self) -> usize21     const fn found(&self) -> usize {
22         self.found
23     }
24 
25     /// Create a new [`UuidError`].
26     ///
27     /// [`UuidError`]: struct.UuidError.html
28     #[inline]
new(expected: usize, found: usize) -> Self29     pub(crate) const fn new(expected: usize, found: usize) -> Self {
30         Error { expected, found }
31     }
32 }
33 
34 impl fmt::Display for Error {
fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result35     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36         write!(
37             f,
38             "invalid bytes length: expected {}, found {}",
39             self.expected(),
40             self.found()
41         )
42     }
43 }
44 
45 #[cfg(feature = "std")]
46 mod std_support {
47     use super::*;
48 
49     use crate::std::error;
50 
51     impl error::Error for Error {}
52 }
53