mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-16 05:31:01 +00:00
Remove serde::error::Error
This commit is contained in:
+24
-16
@@ -96,8 +96,6 @@
|
|||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::error;
|
use std::error;
|
||||||
#[cfg(not(feature = "std"))]
|
|
||||||
use error;
|
|
||||||
|
|
||||||
#[cfg(all(not(feature = "std"), feature = "collections"))]
|
#[cfg(all(not(feature = "std"), feature = "collections"))]
|
||||||
use collections::{String, Vec};
|
use collections::{String, Vec};
|
||||||
@@ -123,20 +121,22 @@ pub use self::ignored_any::IgnoredAny;
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/// The `Error` trait allows `Deserialize` implementations to create descriptive
|
macro_rules! declare_error_trait {
|
||||||
/// error messages belonging to the `Deserializer` against which they are
|
(Error: Sized $(+ $supertrait:path)*) => {
|
||||||
/// currently running.
|
/// The `Error` trait allows `Deserialize` implementations to create descriptive
|
||||||
///
|
/// error messages belonging to the `Deserializer` against which they are
|
||||||
/// Every `Deserializer` declares an `Error` type that encompasses both
|
/// currently running.
|
||||||
/// general-purpose deserialization errors as well as errors specific to the
|
///
|
||||||
/// particular deserialization format. For example the `Error` type of
|
/// Every `Deserializer` declares an `Error` type that encompasses both
|
||||||
/// `serde_json` can represent errors like an invalid JSON escape sequence or an
|
/// general-purpose deserialization errors as well as errors specific to the
|
||||||
/// unterminated string literal, in addition to the error cases that are part of
|
/// particular deserialization format. For example the `Error` type of
|
||||||
/// this trait.
|
/// `serde_json` can represent errors like an invalid JSON escape sequence or an
|
||||||
///
|
/// unterminated string literal, in addition to the error cases that are part of
|
||||||
/// Most deserializers should only need to provide the `Error::custom` method
|
/// this trait.
|
||||||
/// and inherit the default behavior for the other methods.
|
///
|
||||||
pub trait Error: Sized + error::Error {
|
/// Most deserializers should only need to provide the `Error::custom` method
|
||||||
|
/// and inherit the default behavior for the other methods.
|
||||||
|
pub trait Error: Sized $(+ $supertrait)* {
|
||||||
/// Raised when there is general error when deserializing a type.
|
/// Raised when there is general error when deserializing a type.
|
||||||
///
|
///
|
||||||
/// The message should not be capitalized and should not end with a period.
|
/// The message should not be capitalized and should not end with a period.
|
||||||
@@ -246,8 +246,16 @@ pub trait Error: Sized + error::Error {
|
|||||||
fn duplicate_field(field: &'static str) -> Self {
|
fn duplicate_field(field: &'static str) -> Self {
|
||||||
Error::custom(format_args!("duplicate field `{}`", field))
|
Error::custom(format_args!("duplicate field `{}`", field))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
declare_error_trait!(Error: Sized + error::Error);
|
||||||
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
declare_error_trait!(Error: Sized);
|
||||||
|
|
||||||
/// `Unexpected` represents an unexpected invocation of any one of the `Visitor`
|
/// `Unexpected` represents an unexpected invocation of any one of the `Visitor`
|
||||||
/// trait methods.
|
/// trait methods.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ use collections::string::ToString;
|
|||||||
use core::hash::Hash;
|
use core::hash::Hash;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::error;
|
use std::error;
|
||||||
#[cfg(not(feature = "std"))]
|
|
||||||
use error;
|
|
||||||
|
|
||||||
use core::fmt::{self, Display};
|
use core::fmt::{self, Display};
|
||||||
use core::iter::{self, Iterator};
|
use core::iter::{self, Iterator};
|
||||||
@@ -67,16 +65,11 @@ impl Display for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
impl error::Error for Error {
|
impl error::Error for Error {
|
||||||
#[cfg(any(feature = "std", feature = "collections"))]
|
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
&self.err
|
&self.err
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(feature = "std", feature = "collections")))]
|
|
||||||
fn description(&self) -> &str {
|
|
||||||
"Serde deserialization error"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
//! A stand-in for `std::error`
|
|
||||||
use core::fmt::{Debug, Display};
|
|
||||||
|
|
||||||
/// A stand-in for `std::error::Error`, which requires no allocation.
|
|
||||||
pub trait Error: Debug + Display {
|
|
||||||
/// A short description of the error.
|
|
||||||
///
|
|
||||||
/// The description should not contain newlines or sentence-ending
|
|
||||||
/// punctuation, to facilitate embedding in larger user-facing
|
|
||||||
/// strings.
|
|
||||||
fn description(&self) -> &str;
|
|
||||||
|
|
||||||
/// The lower-level cause of this error, if any.
|
|
||||||
fn cause(&self) -> Option<&Error> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -98,8 +98,6 @@ pub mod de;
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub mod iter;
|
pub mod iter;
|
||||||
pub mod ser;
|
pub mod ser;
|
||||||
#[cfg_attr(feature = "std", doc(hidden))]
|
|
||||||
pub mod error;
|
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
// Generated code uses these to support no_std. Not public API.
|
// Generated code uses these to support no_std. Not public API.
|
||||||
|
|||||||
+20
-10
@@ -94,8 +94,6 @@
|
|||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::error;
|
use std::error;
|
||||||
#[cfg(not(feature = "std"))]
|
|
||||||
use error;
|
|
||||||
|
|
||||||
#[cfg(all(feature = "collections", not(feature = "std")))]
|
#[cfg(all(feature = "collections", not(feature = "std")))]
|
||||||
use collections::string::String;
|
use collections::string::String;
|
||||||
@@ -117,16 +115,20 @@ pub use self::impossible::Impossible;
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/// Trait used by `Serialize` implementations to generically construct errors
|
macro_rules! declare_error_trait {
|
||||||
/// belonging to the `Serializer` against which they are currently running.
|
(Error: Sized $(+ $supertrait:path)*) => {
|
||||||
pub trait Error: Sized + error::Error {
|
/// Trait used by `Serialize` implementations to generically construct
|
||||||
/// Raised when a `Serialize` implementation encounters a general error
|
/// errors belonging to the `Serializer` against which they are
|
||||||
/// while serializing a type.
|
/// currently running.
|
||||||
|
pub trait Error: Sized $(+ $supertrait)* {
|
||||||
|
/// Raised when a `Serialize` implementation encounters a general
|
||||||
|
/// error while serializing a type.
|
||||||
///
|
///
|
||||||
/// The message should not be capitalized and should not end with a period.
|
/// The message should not be capitalized and should not end with a
|
||||||
|
/// period.
|
||||||
///
|
///
|
||||||
/// For example, a filesystem `Path` may refuse to serialize itself if it
|
/// For example, a filesystem `Path` may refuse to serialize itself
|
||||||
/// contains invalid UTF-8 data.
|
/// if it contains invalid UTF-8 data.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use serde::ser::{Serialize, Serializer, Error};
|
/// # use serde::ser::{Serialize, Serializer, Error};
|
||||||
@@ -144,8 +146,16 @@ pub trait Error: Sized + error::Error {
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn custom<T: Display>(msg: T) -> Self;
|
fn custom<T: Display>(msg: T) -> Self;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
declare_error_trait!(Error: Sized + error::Error);
|
||||||
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
declare_error_trait!(Error: Sized);
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/// A **data structure** that can be serialized into any data format supported
|
/// A **data structure** that can be serialized into any data format supported
|
||||||
|
|||||||
Reference in New Issue
Block a user