Coverage Report

Created: 2025-11-16 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/uuid-0.8.2/src/error.rs
Line
Count
Source
1
use crate::std::fmt;
2
use crate::{builder, parser};
3
4
/// A general error that can occur when working with UUIDs.
5
// TODO: improve the doc
6
// BODY: This detail should be fine for initial merge
7
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
8
pub struct Error(Inner);
9
10
// TODO: write tests for Error
11
// BODY: not immediately blocking, but should be covered for 1.0
12
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
13
enum Inner {
14
    /// An error occurred while handling [`Uuid`] bytes.
15
    ///
16
    /// See [`BytesError`]
17
    ///
18
    /// [`BytesError`]: struct.BytesError.html
19
    /// [`Uuid`]: struct.Uuid.html
20
    Build(builder::Error),
21
22
    /// An error occurred while parsing a [`Uuid`] string.
23
    ///
24
    /// See [`parser::ParseError`]
25
    ///
26
    /// [`parser::ParseError`]: parser/enum.ParseError.html
27
    /// [`Uuid`]: struct.Uuid.html
28
    Parser(parser::Error),
29
}
30
31
impl From<builder::Error> for Error {
32
0
    fn from(err: builder::Error) -> Self {
33
0
        Error(Inner::Build(err))
34
0
    }
35
}
36
37
impl From<parser::Error> for Error {
38
2.62k
    fn from(err: parser::Error) -> Self {
39
2.62k
        Error(Inner::Parser(err))
40
2.62k
    }
41
}
42
43
impl fmt::Display for Error {
44
0
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45
0
        match self.0 {
46
0
            Inner::Build(ref err) => fmt::Display::fmt(&err, f),
47
0
            Inner::Parser(ref err) => fmt::Display::fmt(&err, f),
48
        }
49
0
    }
50
}
51
52
#[cfg(feature = "std")]
53
mod std_support {
54
    use super::*;
55
    use crate::std::error;
56
57
    impl error::Error for Error {
58
0
        fn source(&self) -> Option<&(dyn error::Error + 'static)> {
59
0
            match self.0 {
60
0
                Inner::Build(ref err) => Some(err),
61
0
                Inner::Parser(ref err) => Some(err),
62
            }
63
0
        }
64
    }
65
}
66
67
#[cfg(test)]
68
mod test_util {
69
    use super::*;
70
71
    impl Error {
72
        pub(crate) fn expect_parser(self) -> parser::Error {
73
            match self.0 {
74
                Inner::Parser(err) => err,
75
                _ => panic!("expected a `parser::Error` variant"),
76
            }
77
        }
78
    }
79
}