Skip to content

Commit 5e9ac38

Browse files
committed
Use non_exhaustive attribute
1 parent 573a5b7 commit 5e9ac38

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
lines changed

src/error.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
///
33
/// Generic parameter `T` is a type of external error returned by the user provided storage
44
#[derive(Debug)]
5+
#[non_exhaustive]
56
pub enum Error<T> {
67
/// A user provided storage instance returned an error during an input/output operation.
78
Io(T),
@@ -25,8 +26,6 @@ pub enum Error<T> {
2526
InvalidFileNameLength,
2627
/// The provided file name contains an invalid character.
2728
UnsupportedFileNameCharacter,
28-
#[doc(hidden)]
29-
_Nonexhaustive,
3029
}
3130

3231
impl<T: IoError> From<T> for Error<T> {
@@ -49,7 +48,6 @@ impl From<Error<std::io::Error>> for std::io::Error {
4948
Error::NotFound => Self::new(std::io::ErrorKind::NotFound, error),
5049
Error::AlreadyExists => Self::new(std::io::ErrorKind::AlreadyExists, error),
5150
Error::CorruptedFileSystem => Self::new(std::io::ErrorKind::InvalidData, error),
52-
_ => Self::new(std::io::ErrorKind::Other, error),
5351
}
5452
}
5553
}
@@ -68,7 +66,6 @@ impl<T: core::fmt::Display> core::fmt::Display for Error<T> {
6866
Error::NotFound => write!(f, "No such file or directory"),
6967
Error::AlreadyExists => write!(f, "File or directory already exists"),
7068
Error::CorruptedFileSystem => write!(f, "Corrupted file system"),
71-
_ => write!(f, "Other error"),
7269
}
7370
}
7471
}

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
#![allow(
6262
clippy::module_name_repetitions,
6363
clippy::cast_possible_truncation,
64-
clippy::manual_non_exhaustive // non_exhaustive attribute was added in Rust 1.40.0
6564
)]
6665

6766
#[macro_use]

src/time.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ const MAX_DAY: u16 = 31;
1616
///
1717
/// Used by `DirEntry` time-related methods.
1818
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
19+
#[non_exhaustive]
1920
pub struct Date {
2021
/// Full year - [1980, 2107]
2122
pub year: u16,
2223
/// Month of the year - [1, 12]
2324
pub month: u16,
2425
/// Day of the month - [1, 31]
2526
pub day: u16,
26-
// Not-public field to disallow direct instantiation of this struct
27-
_dummy: (),
2827
}
2928

3029
impl Date {
@@ -46,7 +45,6 @@ impl Date {
4645
year,
4746
month,
4847
day,
49-
_dummy: (),
5048
}
5149
}
5250

@@ -56,7 +54,6 @@ impl Date {
5654
year,
5755
month,
5856
day,
59-
_dummy: (),
6057
}
6158
}
6259

@@ -69,6 +66,7 @@ impl Date {
6966
///
7067
/// Used by `DirEntry` time-related methods.
7168
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
69+
#[non_exhaustive]
7270
pub struct Time {
7371
/// Hours after midnight - [0, 23]
7472
pub hour: u16,
@@ -78,8 +76,6 @@ pub struct Time {
7876
pub sec: u16,
7977
/// Milliseconds after the second - [0, 999]
8078
pub millis: u16,
81-
// Not-public field to disallow direct instantiation of this struct
82-
_dummy: (),
8379
}
8480

8581
impl Time {
@@ -104,7 +100,6 @@ impl Time {
104100
min,
105101
sec,
106102
millis,
107-
_dummy: (),
108103
}
109104
}
110105

@@ -118,7 +113,6 @@ impl Time {
118113
min,
119114
sec,
120115
millis,
121-
_dummy: (),
122116
}
123117
}
124118

@@ -135,19 +129,18 @@ impl Time {
135129
///
136130
/// Used by `DirEntry` time-related methods.
137131
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
132+
#[non_exhaustive]
138133
pub struct DateTime {
139134
/// A date part
140135
pub date: Date,
141136
// A time part
142137
pub time: Time,
143-
// Not-public field to disallow direct instantiation of this struct
144-
_dummy: (),
145138
}
146139

147140
impl DateTime {
148141
#[must_use]
149142
pub fn new(date: Date, time: Time) -> Self {
150-
Self { date, time, _dummy: () }
143+
Self { date, time }
151144
}
152145

153146
pub(crate) fn decode(dos_date: u16, dos_time: u16, dos_time_hi_res: u8) -> Self {
@@ -184,7 +177,6 @@ impl From<chrono::Date<Local>> for Date {
184177
year,
185178
month: date.month() as u16, // safe cast: value in range [1, 12]
186179
day: date.day() as u16, // safe cast: value in range [1, 31]
187-
_dummy: (),
188180
}
189181
}
190182
}
@@ -194,14 +186,13 @@ impl From<chrono::DateTime<Local>> for DateTime {
194186
fn from(date_time: chrono::DateTime<Local>) -> Self {
195187
let millis_leap = date_time.nanosecond() / 1_000_000; // value in the range [0, 1999] (> 999 if leap second)
196188
let millis = millis_leap.min(999); // during leap second set milliseconds to 999
197-
#[allow(clippy::cast_possible_truncation)]
198189
let date = Date::from(date_time.date());
190+
#[allow(clippy::cast_possible_truncation)]
199191
let time = Time {
200192
hour: date_time.hour() as u16, // safe cast: value in range [0, 23]
201193
min: date_time.minute() as u16, // safe cast: value in range [0, 59]
202194
sec: date_time.second() as u16, // safe cast: value in range [0, 59]
203195
millis: millis as u16, // safe cast: value in range [0, 999]
204-
_dummy: (),
205196
};
206197
Self::new(date, time)
207198
}

0 commit comments

Comments
 (0)