Delete Decoder::read_enum_variant
This commit is contained in:
parent
8def096c4d
commit
75614c06ee
2 changed files with 9 additions and 22 deletions
|
@ -58,14 +58,10 @@ fn decodable_body(
|
||||||
variants.len()
|
variants.len()
|
||||||
);
|
);
|
||||||
quote! {
|
quote! {
|
||||||
::rustc_serialize::Decoder::read_enum_variant(
|
match ::rustc_serialize::Decoder::read_usize(__decoder) {
|
||||||
__decoder,
|
#match_inner
|
||||||
|__decoder, __variant_idx| {
|
_ => panic!(#message),
|
||||||
match __variant_idx {
|
}
|
||||||
#match_inner
|
|
||||||
_ => panic!(#message),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -201,15 +201,6 @@ pub trait Decoder {
|
||||||
fn read_str(&mut self) -> Cow<'_, str>;
|
fn read_str(&mut self) -> Cow<'_, str>;
|
||||||
fn read_raw_bytes_into(&mut self, s: &mut [u8]);
|
fn read_raw_bytes_into(&mut self, s: &mut [u8]);
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn read_enum_variant<T, F>(&mut self, mut f: F) -> T
|
|
||||||
where
|
|
||||||
F: FnMut(&mut Self, usize) -> T,
|
|
||||||
{
|
|
||||||
let disr = self.read_usize();
|
|
||||||
f(self, disr)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read_seq<T, F>(&mut self, f: F) -> T
|
fn read_seq<T, F>(&mut self, f: F) -> T
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut Self, usize) -> T,
|
F: FnOnce(&mut Self, usize) -> T,
|
||||||
|
@ -473,11 +464,11 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for Option<T> {
|
||||||
|
|
||||||
impl<D: Decoder, T: Decodable<D>> Decodable<D> for Option<T> {
|
impl<D: Decoder, T: Decodable<D>> Decodable<D> for Option<T> {
|
||||||
fn decode(d: &mut D) -> Option<T> {
|
fn decode(d: &mut D) -> Option<T> {
|
||||||
d.read_enum_variant(move |this, idx| match idx {
|
match d.read_usize() {
|
||||||
0 => None,
|
0 => None,
|
||||||
1 => Some(Decodable::decode(this)),
|
1 => Some(Decodable::decode(d)),
|
||||||
_ => panic!("Encountered invalid discriminant while decoding `Option`."),
|
_ => panic!("Encountered invalid discriminant while decoding `Option`."),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,11 +487,11 @@ impl<S: Encoder, T1: Encodable<S>, T2: Encodable<S>> Encodable<S> for Result<T1,
|
||||||
|
|
||||||
impl<D: Decoder, T1: Decodable<D>, T2: Decodable<D>> Decodable<D> for Result<T1, T2> {
|
impl<D: Decoder, T1: Decodable<D>, T2: Decodable<D>> Decodable<D> for Result<T1, T2> {
|
||||||
fn decode(d: &mut D) -> Result<T1, T2> {
|
fn decode(d: &mut D) -> Result<T1, T2> {
|
||||||
d.read_enum_variant(|d, disr| match disr {
|
match d.read_usize() {
|
||||||
0 => Ok(T1::decode(d)),
|
0 => Ok(T1::decode(d)),
|
||||||
1 => Err(T2::decode(d)),
|
1 => Err(T2::decode(d)),
|
||||||
_ => panic!("Encountered invalid discriminant while decoding `Result`."),
|
_ => panic!("Encountered invalid discriminant while decoding `Result`."),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue