Unverified Commit 783a9601 authored by stephaneyfx's avatar stephaneyfx Committed by GitHub
Browse files

Always implement Display for Error (#226)

This makes it easier to write code that uses `Error` with or without `std`.
parent c860966e
Pipeline #109890 passed with stages
in 17 minutes and 1 second
......@@ -14,8 +14,7 @@
//! Serialisation.
#[cfg(feature = "std")]
use std::fmt;
use core::fmt;
use core::{mem, ops::Deref, marker::PhantomData, iter::FromIterator, convert::TryFrom, time::Duration};
use core::num::{
NonZeroI8,
......@@ -84,12 +83,19 @@ impl Error {
}
#[cfg(feature = "std")]
impl std::fmt::Display for Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[cfg(not(feature = "std"))]
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("Error")
}
}
#[cfg(feature = "std")]
impl std::error::Error for Error {
fn description(&self) -> &str {
......@@ -501,8 +507,8 @@ impl<T: Decode, E: Decode> Decode for Result<T, E> {
#[derive(Eq, PartialEq, Clone, Copy)]
pub struct OptionBool(pub Option<bool>);
impl core::fmt::Debug for OptionBool {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
impl fmt::Debug for OptionBool {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment