Remove questionable type conversions

This commit is contained in:
David Tolnay 2017-04-04 18:18:47 -07:00
parent 92bc23e484
commit 2795f0ed9d
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 0 additions and 76 deletions

View File

@ -80,12 +80,6 @@ impl<'de> Visitor<'de> for UnitVisitor {
{
Ok(())
}
fn visit_seq<V>(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<E>(self, s: &str) -> Result<bool, E>
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<E>(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<E>(self) -> Result<String, E>
where E: Error
{
Ok(String::new())
}
fn visit_bytes<E>(self, v: &[u8]) -> Result<String, E>
where E: Error
{
@ -503,13 +472,6 @@ macro_rules! seq_impl {
formatter.write_str("a sequence")
}
#[inline]
fn visit_unit<E>(self) -> Result<Self::Value, E>
where E: Error,
{
Ok($ctor)
}
#[inline]
fn visit_seq<V>(self, mut $visitor: V) -> Result<Self::Value, V::Error>
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<E>(self) -> Result<[T; 0], E>
where E: Error
{
Ok([])
}
#[inline]
fn visit_seq<V>(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<E>(self) -> Result<Self::Value, E>
where E: Error,
{
Ok($ctor)
}
#[inline]
fn visit_map<Visitor>(self, mut $visitor: Visitor) -> Result<Self::Value, Visitor::Error>
where Visitor: MapVisitor<'de>,

View File

@ -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)
}