Remove "_error" from de::Error::*_error

This commit is contained in:
Erick Tryzelaar
2015-08-06 17:47:44 -07:00
parent 0482b756e8
commit 2aeb51ad51
13 changed files with 100 additions and 100 deletions
+14 -14
View File
@@ -85,7 +85,7 @@ impl Visitor for BoolVisitor {
match s.trim() {
"true" => Ok(true),
"false" => Ok(false),
_ => Err(Error::syntax_error()),
_ => Err(Error::syntax()),
}
}
}
@@ -108,7 +108,7 @@ macro_rules! impl_deserialize_num_method {
{
match FromPrimitive::$from_method(v) {
Some(v) => Ok(v),
None => Err(Error::syntax_error()),
None => Err(Error::syntax()),
}
}
}
@@ -149,7 +149,7 @@ impl<
fn visit_str<E>(&mut self, v: &str) -> Result<T, E>
where E: Error,
{
str::FromStr::from_str(v.trim()).or(Err(Error::syntax_error()))
str::FromStr::from_str(v.trim()).or(Err(Error::syntax()))
}
}
@@ -200,12 +200,12 @@ impl Visitor for CharVisitor {
let mut iter = v.chars();
if let Some(v) = iter.next() {
if iter.next().is_some() {
Err(Error::syntax_error())
Err(Error::syntax())
} else {
Ok(v)
}
} else {
Err(Error::end_of_stream_error())
Err(Error::end_of_stream())
}
}
}
@@ -243,7 +243,7 @@ impl Visitor for StringVisitor {
{
match str::from_utf8(v) {
Ok(s) => Ok(s.to_string()),
Err(_) => Err(Error::syntax_error()),
Err(_) => Err(Error::syntax()),
}
}
@@ -252,7 +252,7 @@ impl Visitor for StringVisitor {
{
match String::from_utf8(v) {
Ok(s) => Ok(s),
Err(_) => Err(Error::syntax_error()),
Err(_) => Err(Error::syntax()),
}
}
}
@@ -495,7 +495,7 @@ macro_rules! array_impls {
$(
let $name = match try!(visitor.visit()) {
Some(val) => val,
None => { return Err(Error::end_of_stream_error()); }
None => { return Err(Error::end_of_stream()); }
};
)+;
@@ -593,7 +593,7 @@ macro_rules! tuple_impls {
$(
let $name = match try!(visitor.visit()) {
Some(value) => value,
None => { return Err(Error::end_of_stream_error()); }
None => { return Err(Error::end_of_stream()); }
};
)+;
@@ -848,7 +848,7 @@ impl<T> Deserialize for NonZero<T> where T: Deserialize + PartialEq + Zeroable +
fn deserialize<D>(deserializer: &mut D) -> Result<NonZero<T>, D::Error> where D: Deserializer {
let value = try!(Deserialize::deserialize(deserializer));
if value == Zero::zero() {
return Err(Error::syntax_error())
return Err(Error::syntax())
}
unsafe {
Ok(NonZero::new(value))
@@ -881,7 +881,7 @@ impl<T, E> Deserialize for Result<T, E> where T: Deserialize, E: Deserialize {
match value {
0 => Ok(Field::Ok),
1 => Ok(Field::Err),
_ => Err(Error::unknown_field_error(&value.to_string())),
_ => Err(Error::unknown_field(&value.to_string())),
}
}
@@ -889,7 +889,7 @@ impl<T, E> Deserialize for Result<T, E> where T: Deserialize, E: Deserialize {
match value {
"Ok" => Ok(Field::Ok),
"Err" => Ok(Field::Err),
_ => Err(Error::unknown_field_error(value)),
_ => Err(Error::unknown_field(value)),
}
}
@@ -899,8 +899,8 @@ impl<T, E> Deserialize for Result<T, E> where T: Deserialize, E: Deserialize {
b"Err" => Ok(Field::Err),
_ => {
match str::from_utf8(value) {
Ok(value) => Err(Error::unknown_field_error(value)),
Err(_) => Err(Error::syntax_error()),
Ok(value) => Err(Error::unknown_field(value)),
Err(_) => Err(Error::syntax()),
}
}
}
+21 -21
View File
@@ -6,13 +6,13 @@ pub mod value;
///////////////////////////////////////////////////////////////////////////////
pub trait Error {
fn syntax_error() -> Self;
fn syntax() -> Self;
fn end_of_stream_error() -> Self;
fn end_of_stream() -> Self;
fn unknown_field_error(field: &str) -> Self;
fn unknown_field(field: &str) -> Self;
fn missing_field_error(field: &'static str) -> Self;
fn missing_field(field: &'static str) -> Self;
}
///////////////////////////////////////////////////////////////////////////////
@@ -273,7 +273,7 @@ pub trait Deserializer {
_visitor: V) -> Result<V::Value, Self::Error>
where V: EnumVisitor,
{
Err(Error::syntax_error())
Err(Error::syntax())
}
/// This method hints that the `Deserialize` type is expecting a `Vec<u8>`. This allows
@@ -304,7 +304,7 @@ pub trait Visitor {
fn visit_bool<E>(&mut self, _v: bool) -> Result<Self::Value, E>
where E: Error,
{
Err(Error::syntax_error())
Err(Error::syntax())
}
fn visit_isize<E>(&mut self, v: isize) -> Result<Self::Value, E>
@@ -334,7 +334,7 @@ pub trait Visitor {
fn visit_i64<E>(&mut self, _v: i64) -> Result<Self::Value, E>
where E: Error,
{
Err(Error::syntax_error())
Err(Error::syntax())
}
fn visit_usize<E>(&mut self, v: usize) -> Result<Self::Value, E>
@@ -364,7 +364,7 @@ pub trait Visitor {
fn visit_u64<E>(&mut self, _v: u64) -> Result<Self::Value, E>
where E: Error,
{
Err(Error::syntax_error())
Err(Error::syntax())
}
fn visit_f32<E>(&mut self, v: f32) -> Result<Self::Value, E>
@@ -376,7 +376,7 @@ pub trait Visitor {
fn visit_f64<E>(&mut self, _v: f64) -> Result<Self::Value, E>
where E: Error,
{
Err(Error::syntax_error())
Err(Error::syntax())
}
#[inline]
@@ -391,7 +391,7 @@ pub trait Visitor {
fn visit_str<E>(&mut self, _v: &str) -> Result<Self::Value, E>
where E: Error,
{
Err(Error::syntax_error())
Err(Error::syntax())
}
#[inline]
@@ -404,7 +404,7 @@ pub trait Visitor {
fn visit_unit<E>(&mut self) -> Result<Self::Value, E>
where E: Error,
{
Err(Error::syntax_error())
Err(Error::syntax())
}
#[inline]
@@ -417,37 +417,37 @@ pub trait Visitor {
fn visit_none<E>(&mut self) -> Result<Self::Value, E>
where E: Error,
{
Err(Error::syntax_error())
Err(Error::syntax())
}
fn visit_some<D>(&mut self, _deserializer: &mut D) -> Result<Self::Value, D::Error>
where D: Deserializer,
{
Err(Error::syntax_error())
Err(Error::syntax())
}
fn visit_newtype_struct<D>(&mut self, _deserializer: &mut D) -> Result<Self::Value, D::Error>
where D: Deserializer,
{
Err(Error::syntax_error())
Err(Error::syntax())
}
fn visit_seq<V>(&mut self, _visitor: V) -> Result<Self::Value, V::Error>
where V: SeqVisitor,
{
Err(Error::syntax_error())
Err(Error::syntax())
}
fn visit_map<V>(&mut self, _visitor: V) -> Result<Self::Value, V::Error>
where V: MapVisitor,
{
Err(Error::syntax_error())
Err(Error::syntax())
}
fn visit_bytes<E>(&mut self, _v: &[u8]) -> Result<Self::Value, E>
where E: Error,
{
Err(Error::syntax_error())
Err(Error::syntax())
}
fn visit_byte_buf<E>(&mut self, v: Vec<u8>) -> Result<Self::Value, E>
@@ -529,7 +529,7 @@ pub trait MapVisitor {
fn missing_field<V>(&mut self, field: &'static str) -> Result<V, Self::Error>
where V: Deserialize,
{
Err(Error::missing_field_error(field))
Err(Error::missing_field(field))
}
}
@@ -593,7 +593,7 @@ pub trait VariantVisitor {
/// `visit_unit` is called when deserializing a variant with no values.
fn visit_unit(&mut self) -> Result<(), Self::Error> {
Err(Error::syntax_error())
Err(Error::syntax())
}
/// `visit_newtype` is called when deserializing a variant with a single value. By default this
@@ -612,7 +612,7 @@ pub trait VariantVisitor {
_visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor
{
Err(Error::syntax_error())
Err(Error::syntax())
}
/// `visit_struct` is called when deserializing a struct-like variant.
@@ -621,7 +621,7 @@ pub trait VariantVisitor {
_visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor
{
Err(Error::syntax_error())
Err(Error::syntax())
}
}
+12 -12
View File
@@ -24,10 +24,10 @@ pub enum Error {
}
impl de::Error for Error {
fn syntax_error() -> Self { Error::SyntaxError }
fn end_of_stream_error() -> Self { Error::EndOfStreamError }
fn unknown_field_error(field: &str) -> Self { Error::UnknownFieldError(field.to_string()) }
fn missing_field_error(field: &'static str) -> Self { Error::MissingFieldError(field) }
fn syntax() -> Self { Error::SyntaxError }
fn end_of_stream() -> Self { Error::EndOfStreamError }
fn unknown_field(field: &str) -> Self { Error::UnknownFieldError(field.to_string()) }
fn missing_field(field: &'static str) -> Self { Error::MissingFieldError(field) }
}
///////////////////////////////////////////////////////////////////////////////
@@ -89,7 +89,7 @@ macro_rules! primitive_deserializer {
{
match self.0.take() {
Some(v) => visitor.$method(v),
None => Err(de::Error::end_of_stream_error()),
None => Err(de::Error::end_of_stream()),
}
}
}
@@ -132,7 +132,7 @@ impl<'a> de::Deserializer for StrDeserializer<'a> {
{
match self.0.take() {
Some(v) => visitor.visit_str(v),
None => Err(de::Error::end_of_stream_error()),
None => Err(de::Error::end_of_stream()),
}
}
@@ -181,7 +181,7 @@ impl de::Deserializer for StringDeserializer {
{
match self.0.take() {
Some(string) => visitor.visit_string(string),
None => Err(de::Error::end_of_stream_error()),
None => Err(de::Error::end_of_stream()),
}
}
@@ -261,7 +261,7 @@ impl<I, T> de::SeqVisitor for SeqDeserializer<I>
if self.len == 0 {
Ok(())
} else {
Err(de::Error::end_of_stream_error())
Err(de::Error::end_of_stream())
}
}
@@ -374,7 +374,7 @@ impl<I, K, V> de::MapVisitor for MapDeserializer<I, K, V>
let mut de = value.into_deserializer();
de::Deserialize::deserialize(&mut de)
}
None => Err(de::Error::syntax_error())
None => Err(de::Error::syntax())
}
}
@@ -382,7 +382,7 @@ impl<I, K, V> de::MapVisitor for MapDeserializer<I, K, V>
if self.len == 0 {
Ok(())
} else {
Err(de::Error::end_of_stream_error())
Err(de::Error::end_of_stream())
}
}
@@ -438,7 +438,7 @@ impl<'a> de::Deserializer for BytesDeserializer<'a> {
{
match self.0.take() {
Some(bytes) => visitor.visit_bytes(bytes),
None => Err(de::Error::end_of_stream_error()),
None => Err(de::Error::end_of_stream()),
}
}
}
@@ -465,7 +465,7 @@ impl de::Deserializer for ByteBufDeserializer {
{
match self.0.take() {
Some(bytes) => visitor.visit_byte_buf(bytes),
None => Err(de::Error::end_of_stream_error()),
None => Err(de::Error::end_of_stream()),
}
}
}