Skip to content

Commit 4910c3c

Browse files
Jturnerusanvinson
authored andcommitted
use the enum for the error directly instead of the struct
1 parent aacaf3a commit 4910c3c

File tree

1 file changed

+9
-25
lines changed

1 file changed

+9
-25
lines changed

src/lib/efivar/types/efi_guid_error.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,35 @@ use std::error::Error;
22
use std::fmt;
33

44
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
5-
pub enum EfiGuidErrorKind {
5+
pub enum EfiGuidError {
66
BadFormat,
77
SliceLengthTooLong,
88
SliceLengthTooShort,
99
VecLengthTooLong,
1010
VecLengthTooShort,
1111
}
1212

13-
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
14-
pub struct EfiGuidError(EfiGuidErrorKind);
15-
16-
impl Error for EfiGuidError {}
17-
1813
impl fmt::Display for EfiGuidError {
19-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20-
match self.0 {
21-
EfiGuidErrorKind::BadFormat => write!(
14+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
15+
match self {
16+
Self::BadFormat => write!(
2217
f,
2318
"bad format. Correct format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
2419
),
25-
EfiGuidErrorKind::SliceLengthTooLong => {
20+
Self::SliceLengthTooLong => {
2621
write!(f, "source slice too long. Slice must have a size of 16")
2722
}
28-
EfiGuidErrorKind::SliceLengthTooShort => {
23+
Self::SliceLengthTooShort => {
2924
write!(f, "source slice too short. Slice must have a size of 16")
3025
}
31-
EfiGuidErrorKind::VecLengthTooLong => {
26+
Self::VecLengthTooLong => {
3227
write!(f, "source vector too long. Vector must have a size of 16")
3328
}
34-
EfiGuidErrorKind::VecLengthTooShort => {
29+
Self::VecLengthTooShort => {
3530
write!(f, "source vector too short. Vector must have a size of 16")
3631
}
3732
}
3833
}
3934
}
4035

41-
pub const BAD_FORMAT: EfiGuidError = EfiGuidError(EfiGuidErrorKind::BadFormat);
42-
43-
pub const SRC_SLICE_LENGTH_TOO_LONG: EfiGuidError =
44-
EfiGuidError(EfiGuidErrorKind::SliceLengthTooLong);
45-
46-
pub const SRC_SLICE_LENGTH_TOO_SHORT: EfiGuidError =
47-
EfiGuidError(EfiGuidErrorKind::SliceLengthTooShort);
48-
49-
pub const SRC_VEC_LENGTH_TOO_LONG: EfiGuidError = EfiGuidError(EfiGuidErrorKind::VecLengthTooLong);
50-
51-
pub const SRC_VEC_LENGTH_TOO_SHORT: EfiGuidError =
52-
EfiGuidError(EfiGuidErrorKind::VecLengthTooShort);
36+
impl Error for EfiGuidError {};

0 commit comments

Comments
 (0)