From 2795f0ed9d5dc63b8ab1c2b64368941c42a852c4 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 4 Apr 2017 18:18:47 -0700 Subject: [PATCH] Remove questionable type conversions --- serde/src/de/impls.rs | 52 ------------------------------------------- serde/src/utils.rs | 24 -------------------- 2 files changed, 76 deletions(-) diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index 9b6f1f5d..1aa91db5 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -80,12 +80,6 @@ impl<'de> Visitor<'de> for UnitVisitor { { Ok(()) } - - fn visit_seq(self, _: V) -> Result<(), V::Error> - where V: SeqVisitor<'de> - { - Ok(()) - } } impl<'de> Deserialize<'de> for () { @@ -113,16 +107,6 @@ impl<'de> Visitor<'de> for BoolVisitor { { Ok(v) } - - fn visit_str(self, s: &str) -> Result - where E: Error - { - match s.trim_matches(::utils::Pattern_White_Space) { - "true" => Ok(true), - "false" => Ok(false), - _ => Err(Error::invalid_type(Unexpected::Str(s), &self)), - } - } } impl<'de> Deserialize<'de> for bool { @@ -175,15 +159,6 @@ macro_rules! impl_deserialize_num { impl_deserialize_num_method!($ty, u64, visit_u64, from_u64, Unsigned, u64); impl_deserialize_num_method!($ty, f32, visit_f32, from_f32, Float, f64); impl_deserialize_num_method!($ty, f64, visit_f64, from_f64, Float, f64); - - #[inline] - fn visit_str(self, s: &str) -> Result<$ty, E> - where E: Error, - { - str::FromStr::from_str(s.trim_matches(::utils::Pattern_White_Space)).or_else(|_| { - Err(Error::invalid_type(Unexpected::Str(s), &self)) - }) - } } deserializer.$method(PrimitiveVisitor) @@ -269,12 +244,6 @@ impl<'de> Visitor<'de> for StringVisitor { Ok(v) } - fn visit_unit(self) -> Result - where E: Error - { - Ok(String::new()) - } - fn visit_bytes(self, v: &[u8]) -> Result where E: Error { @@ -503,13 +472,6 @@ macro_rules! seq_impl { formatter.write_str("a sequence") } - #[inline] - fn visit_unit(self) -> Result - where E: Error, - { - Ok($ctor) - } - #[inline] fn visit_seq(self, mut $visitor: V) -> Result where V: SeqVisitor<'de>, @@ -613,13 +575,6 @@ impl<'de, T> Visitor<'de> for ArrayVisitor<[T; 0]> formatter.write_str("an empty array") } - #[inline] - fn visit_unit(self) -> Result<[T; 0], E> - where E: Error - { - Ok([]) - } - #[inline] fn visit_seq(self, _: V) -> Result<[T; 0], V::Error> where V: SeqVisitor<'de> @@ -819,13 +774,6 @@ macro_rules! map_impl { formatter.write_str("a map") } - #[inline] - fn visit_unit(self) -> Result - where E: Error, - { - Ok($ctor) - } - #[inline] fn visit_map(self, mut $visitor: Visitor) -> Result where Visitor: MapVisitor<'de>, diff --git a/serde/src/utils.rs b/serde/src/utils.rs index 927d1256..4e81616a 100644 --- a/serde/src/utils.rs +++ b/serde/src/utils.rs @@ -48,27 +48,3 @@ impl EncodeUtf8 { ::core::str::from_utf8(&self.buf[self.pos..]).unwrap() } } - -#[allow(non_upper_case_globals)] -const Pattern_White_Space_table: &'static [(char, char)] = &[('\u{9}', '\u{d}'), - ('\u{20}', '\u{20}'), - ('\u{85}', '\u{85}'), - ('\u{200e}', '\u{200f}'), - ('\u{2028}', '\u{2029}')]; - -fn bsearch_range_table(c: char, r: &'static [(char, char)]) -> bool { - use core::cmp::Ordering::{Equal, Less, Greater}; - r.binary_search_by(|&(lo, hi)| if c < lo { - Greater - } else if hi < c { - Less - } else { - Equal - }) - .is_ok() -} - -#[allow(non_snake_case)] -pub fn Pattern_White_Space(c: char) -> bool { - bsearch_range_table(c, Pattern_White_Space_table) -}