mirror of
https://github.com/serde-rs/json.git
synced 2025-10-02 23:35:59 +00:00
Remove unnecessary box trait object from io error repr
This commit is contained in:
parent
e83673adea
commit
67857df516
@ -8,36 +8,26 @@ pub enum ErrorKind {
|
|||||||
Other,
|
Other,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Error {
|
pub struct Error(&'static str);
|
||||||
repr: Box<dyn ErrorRepr + Send + Sync>,
|
|
||||||
}
|
|
||||||
|
|
||||||
trait ErrorRepr: Display + Debug {}
|
|
||||||
impl<T: Display + Debug> ErrorRepr for T {}
|
|
||||||
|
|
||||||
impl Display for Error {
|
impl Display for Error {
|
||||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
Display::fmt(self.repr.as_ref(), formatter)
|
Display::fmt(self.0, formatter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for Error {
|
impl Debug for Error {
|
||||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
Debug::fmt(self.repr.as_ref(), formatter)
|
Debug::fmt(self.0, formatter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl serde::de::StdError for Error {}
|
impl serde::de::StdError for Error {}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
pub(crate) fn new<E>(kind: ErrorKind, error: E) -> Error
|
pub(crate) fn new(kind: ErrorKind, error: &'static str) -> Error {
|
||||||
where
|
|
||||||
E: Display + Debug + Send + Sync + 'static,
|
|
||||||
{
|
|
||||||
let _ = kind;
|
let _ = kind;
|
||||||
Error {
|
Error(error)
|
||||||
repr: Box::new(error),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user