Skip to content

Commit 38e6dad

Browse files
Delete Decoder::read_option
1 parent 24dc052 commit 38e6dad

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

compiler/rustc_serialize/src/serialize.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,18 +210,6 @@ pub trait Decoder {
210210
f(self, disr)
211211
}
212212

213-
// Specialized types:
214-
fn read_option<T, F>(&mut self, mut f: F) -> T
215-
where
216-
F: FnMut(&mut Self, bool) -> T,
217-
{
218-
self.read_enum_variant(move |this, idx| match idx {
219-
0 => f(this, false),
220-
1 => f(this, true),
221-
_ => panic!("read_option: expected 0 for None or 1 for Some"),
222-
})
223-
}
224-
225213
fn read_seq<T, F>(&mut self, f: F) -> T
226214
where
227215
F: FnOnce(&mut Self, usize) -> T,
@@ -501,7 +489,11 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for Option<T> {
501489

502490
impl<D: Decoder, T: Decodable<D>> Decodable<D> for Option<T> {
503491
fn decode(d: &mut D) -> Option<T> {
504-
d.read_option(|d, b| if b { Some(Decodable::decode(d)) } else { None })
492+
d.read_enum_variant(move |this, idx| match idx {
493+
0 => None,
494+
1 => Some(Decodable::decode(this)),
495+
_ => panic!("Encountered invalid discriminant while decoding `Option`."),
496+
})
505497
}
506498
}
507499

0 commit comments

Comments
 (0)