Skip to content

Commit f973cd4

Browse files
authored
enum: use #[non_exhaustive] instead of #[doc(hidden)] variant
This was introduced in Rust 1.40, which is below the MSRV of 1.73. Closes BurntSushi#325
1 parent eca0fed commit f973cd4

File tree

5 files changed

+6
-51
lines changed

5 files changed

+6
-51
lines changed

csv-core/src/lib.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,12 @@ mod writer;
115115
/// Use this to specify the record terminator while parsing CSV. The default is
116116
/// CRLF, which treats `\r`, `\n` or `\r\n` as a single record terminator.
117117
#[derive(Clone, Copy, Debug)]
118+
#[non_exhaustive]
118119
pub enum Terminator {
119120
/// Parses `\r`, `\n` or `\r\n` as a single record terminator.
120121
CRLF,
121122
/// Parses the byte given as a record terminator.
122123
Any(u8),
123-
/// Hints that destructuring should not be exhaustive.
124-
///
125-
/// This enum may grow additional variants, so this makes sure clients
126-
/// don't count on exhaustive matching. (Otherwise, adding a new variant
127-
/// could break existing code.)
128-
#[doc(hidden)]
129-
__Nonexhaustive,
130124
}
131125

132126
impl Terminator {
@@ -135,15 +129,13 @@ impl Terminator {
135129
match *self {
136130
Terminator::CRLF => true,
137131
Terminator::Any(_) => false,
138-
_ => unreachable!(),
139132
}
140133
}
141134

142135
fn equals(&self, other: u8) -> bool {
143136
match *self {
144137
Terminator::CRLF => other == b'\r' || other == b'\n',
145138
Terminator::Any(b) => other == b,
146-
_ => unreachable!(),
147139
}
148140
}
149141
}
@@ -156,6 +148,7 @@ impl Default for Terminator {
156148

157149
/// The quoting style to use when writing CSV data.
158150
#[derive(Clone, Copy, Debug)]
151+
#[non_exhaustive]
159152
pub enum QuoteStyle {
160153
/// This puts quotes around every field. Always.
161154
Always,
@@ -173,13 +166,6 @@ pub enum QuoteStyle {
173166
NonNumeric,
174167
/// This *never* writes quotes, even if it would produce invalid CSV data.
175168
Never,
176-
/// Hints that destructuring should not be exhaustive.
177-
///
178-
/// This enum may grow additional variants, so this makes sure clients
179-
/// don't count on exhaustive matching. (Otherwise, adding a new variant
180-
/// could break existing code.)
181-
#[doc(hidden)]
182-
__Nonexhaustive,
183169
}
184170

185171
impl Default for QuoteStyle {

csv-core/src/reader.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,6 @@ impl Reader {
819819
self.dfa.classes.add(b'\r');
820820
self.dfa.classes.add(b'\n');
821821
}
822-
_ => unreachable!(),
823822
}
824823
// Build the DFA transition table by computing the DFA state for all
825824
// possible combinations of state and input byte.

csv-core/src/writer.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ impl WriterBuilder {
5555
Any(b) => {
5656
wtr.requires_quotes[b as usize] = true;
5757
}
58-
_ => unreachable!(),
5958
}
6059
// If the first field of a row starts with a comment character,
6160
// it needs to be quoted, or the row will not be readable later.
@@ -396,7 +395,6 @@ impl Writer {
396395
let (res, o) = match self.term {
397396
Terminator::CRLF => write_pessimistic(&[b'\r', b'\n'], output),
398397
Terminator::Any(b) => write_pessimistic(&[b], output),
399-
_ => unreachable!(),
400398
};
401399
if o == 0 {
402400
return (res, nout);
@@ -446,7 +444,6 @@ impl Writer {
446444
QuoteStyle::Never => false,
447445
QuoteStyle::NonNumeric => is_non_numeric(input),
448446
QuoteStyle::Necessary => self.needs_quotes(input),
449-
_ => unreachable!(),
450447
}
451448
}
452449

src/error.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ impl Error {
5757

5858
/// The specific type of an error.
5959
#[derive(Debug)]
60+
#[non_exhaustive]
6061
pub enum ErrorKind {
6162
/// An I/O error that occurred while reading CSV data.
6263
Io(io::Error),
@@ -97,13 +98,6 @@ pub enum ErrorKind {
9798
/// The deserialization error.
9899
err: DeserializeError,
99100
},
100-
/// Hints that destructuring should not be exhaustive.
101-
///
102-
/// This enum may grow additional variants, so this makes sure clients
103-
/// don't count on exhaustive matching. (Otherwise, adding a new variant
104-
/// could break existing code.)
105-
#[doc(hidden)]
106-
__Nonexhaustive,
107101
}
108102

109103
impl ErrorKind {
@@ -197,7 +191,6 @@ impl fmt::Display for Error {
197191
pos.byte(),
198192
err
199193
),
200-
_ => unreachable!(),
201194
}
202195
}
203196
}

src/lib.rs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ mod writer;
167167

168168
/// The quoting style to use when writing CSV data.
169169
#[derive(Clone, Copy, Debug)]
170+
#[non_exhaustive]
170171
pub enum QuoteStyle {
171172
/// This puts quotes around every field. Always.
172173
Always,
@@ -184,13 +185,6 @@ pub enum QuoteStyle {
184185
NonNumeric,
185186
/// This *never* writes quotes, even if it would produce invalid CSV data.
186187
Never,
187-
/// Hints that destructuring should not be exhaustive.
188-
///
189-
/// This enum may grow additional variants, so this makes sure clients
190-
/// don't count on exhaustive matching. (Otherwise, adding a new variant
191-
/// could break existing code.)
192-
#[doc(hidden)]
193-
__Nonexhaustive,
194188
}
195189

196190
impl QuoteStyle {
@@ -200,7 +194,6 @@ impl QuoteStyle {
200194
QuoteStyle::Necessary => csv_core::QuoteStyle::Necessary,
201195
QuoteStyle::NonNumeric => csv_core::QuoteStyle::NonNumeric,
202196
QuoteStyle::Never => csv_core::QuoteStyle::Never,
203-
_ => unreachable!(),
204197
}
205198
}
206199
}
@@ -216,18 +209,12 @@ impl Default for QuoteStyle {
216209
/// Use this to specify the record terminator while parsing CSV. The default is
217210
/// CRLF, which treats `\r`, `\n` or `\r\n` as a single record terminator.
218211
#[derive(Clone, Copy, Debug)]
212+
#[non_exhaustive]
219213
pub enum Terminator {
220214
/// Parses `\r`, `\n` or `\r\n` as a single record terminator.
221215
CRLF,
222216
/// Parses the byte given as a record terminator.
223217
Any(u8),
224-
/// Hints that destructuring should not be exhaustive.
225-
///
226-
/// This enum may grow additional variants, so this makes sure clients
227-
/// don't count on exhaustive matching. (Otherwise, adding a new variant
228-
/// could break existing code.)
229-
#[doc(hidden)]
230-
__Nonexhaustive,
231218
}
232219

233220
impl Terminator {
@@ -236,7 +223,6 @@ impl Terminator {
236223
match self {
237224
Terminator::CRLF => csv_core::Terminator::CRLF,
238225
Terminator::Any(b) => csv_core::Terminator::Any(b),
239-
_ => unreachable!(),
240226
}
241227
}
242228
}
@@ -249,6 +235,7 @@ impl Default for Terminator {
249235

250236
/// The whitespace preservation behaviour when reading CSV data.
251237
#[derive(Clone, Copy, Debug, PartialEq)]
238+
#[non_exhaustive]
252239
pub enum Trim {
253240
/// Preserves fields and headers. This is the default.
254241
None,
@@ -258,13 +245,6 @@ pub enum Trim {
258245
Fields,
259246
/// Trim whitespace from fields and headers.
260247
All,
261-
/// Hints that destructuring should not be exhaustive.
262-
///
263-
/// This enum may grow additional variants, so this makes sure clients
264-
/// don't count on exhaustive matching. (Otherwise, adding a new variant
265-
/// could break existing code.)
266-
#[doc(hidden)]
267-
__Nonexhaustive,
268248
}
269249

270250
impl Trim {

0 commit comments

Comments
 (0)