style: use Self:: instead of type aliases in error impls
Use instead of 'use FooError as E' when pattern matching on the same type in Display/Error trait implementations.
This commit is contained in:
parent
855299ab7e
commit
0a0e23fedf
|
@ -471,14 +471,12 @@ impl From<Infallible> for ParseOutPointError {
|
||||||
#[cfg(feature = "hex")]
|
#[cfg(feature = "hex")]
|
||||||
impl fmt::Display for ParseOutPointError {
|
impl fmt::Display for ParseOutPointError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
use ParseOutPointError as E;
|
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
E::Txid(ref e) => write_err!(f, "error parsing TXID"; e),
|
Self::Txid(ref e) => write_err!(f, "error parsing TXID"; e),
|
||||||
E::Vout(ref e) => write_err!(f, "error parsing vout"; e),
|
Self::Vout(ref e) => write_err!(f, "error parsing vout"; e),
|
||||||
E::Format => write!(f, "OutPoint not in <txid>:<vout> format"),
|
Self::Format => write!(f, "OutPoint not in <txid>:<vout> format"),
|
||||||
E::TooLong => write!(f, "vout should be at most 10 digits"),
|
Self::TooLong => write!(f, "vout should be at most 10 digits"),
|
||||||
E::VoutNotCanonical => write!(f, "no leading zeroes or + allowed in vout part"),
|
Self::VoutNotCanonical => write!(f, "no leading zeroes or + allowed in vout part"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -487,12 +485,10 @@ impl fmt::Display for ParseOutPointError {
|
||||||
#[cfg(feature = "hex")]
|
#[cfg(feature = "hex")]
|
||||||
impl std::error::Error for ParseOutPointError {
|
impl std::error::Error for ParseOutPointError {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use ParseOutPointError as E;
|
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
E::Txid(e) => Some(e),
|
Self::Txid(e) => Some(e),
|
||||||
E::Vout(e) => Some(e),
|
Self::Vout(e) => Some(e),
|
||||||
E::Format | E::TooLong | E::VoutNotCanonical => None,
|
Self::Format | Self::TooLong | Self::VoutNotCanonical => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -337,11 +337,9 @@ impl From<Infallible> for ParseDenominationError {
|
||||||
|
|
||||||
impl fmt::Display for ParseDenominationError {
|
impl fmt::Display for ParseDenominationError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
use ParseDenominationError as E;
|
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
E::Unknown(ref e) => write_err!(f, "denomination parse error"; e),
|
Self::Unknown(ref e) => write_err!(f, "denomination parse error"; e),
|
||||||
E::PossiblyConfusing(ref e) => write_err!(f, "denomination parse error"; e),
|
Self::PossiblyConfusing(ref e) => write_err!(f, "denomination parse error"; e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -349,10 +347,9 @@ impl fmt::Display for ParseDenominationError {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for ParseDenominationError {
|
impl std::error::Error for ParseDenominationError {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use ParseDenominationError as E;
|
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
E::Unknown(_) | E::PossiblyConfusing(_) => None,
|
Self::Unknown(_) | Self::PossiblyConfusing(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -377,10 +377,9 @@ impl ParseError {
|
||||||
) -> fmt::Result {
|
) -> fmt::Result {
|
||||||
use core::num::IntErrorKind;
|
use core::num::IntErrorKind;
|
||||||
|
|
||||||
use ParseError as E;
|
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
E::ParseInt(ParseIntError { input, bits: _, is_signed: _, source })
|
Self::ParseInt(ParseIntError { input, bits: _, is_signed: _, source })
|
||||||
if *source.kind() == IntErrorKind::PosOverflow =>
|
if *source.kind() == IntErrorKind::PosOverflow =>
|
||||||
{
|
{
|
||||||
// Outputs "failed to parse <input_string> as absolute Height/MedianTimePast (<subject> is above limit <upper_bound>)"
|
// Outputs "failed to parse <input_string> as absolute Height/MedianTimePast (<subject> is above limit <upper_bound>)"
|
||||||
|
@ -392,7 +391,7 @@ impl ParseError {
|
||||||
upper_bound
|
upper_bound
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
E::ParseInt(ParseIntError { input, bits: _, is_signed: _, source })
|
Self::ParseInt(ParseIntError { input, bits: _, is_signed: _, source })
|
||||||
if *source.kind() == IntErrorKind::NegOverflow =>
|
if *source.kind() == IntErrorKind::NegOverflow =>
|
||||||
{
|
{
|
||||||
// Outputs "failed to parse <input_string> as absolute Height/MedianTimePast (<subject> is below limit <lower_bound>)"
|
// Outputs "failed to parse <input_string> as absolute Height/MedianTimePast (<subject> is below limit <lower_bound>)"
|
||||||
|
@ -404,7 +403,7 @@ impl ParseError {
|
||||||
lower_bound
|
lower_bound
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
E::ParseInt(ParseIntError { input, bits: _, is_signed: _, source: _ }) => {
|
Self::ParseInt(ParseIntError { input, bits: _, is_signed: _, source: _ }) => {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"{} ({})",
|
"{} ({})",
|
||||||
|
@ -412,10 +411,10 @@ impl ParseError {
|
||||||
subject
|
subject
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
E::Conversion(value) if *value < i64::from(lower_bound) => {
|
Self::Conversion(value) if *value < i64::from(lower_bound) => {
|
||||||
write!(f, "{} {} is below limit {}", subject, value, lower_bound)
|
write!(f, "{} {} is below limit {}", subject, value, lower_bound)
|
||||||
}
|
}
|
||||||
E::Conversion(value) => {
|
Self::Conversion(value) => {
|
||||||
write!(f, "{} {} is above limit {}", subject, value, upper_bound)
|
write!(f, "{} {} is above limit {}", subject, value, upper_bound)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -426,17 +425,16 @@ impl ParseError {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
use core::num::IntErrorKind;
|
use core::num::IntErrorKind;
|
||||||
|
|
||||||
use ParseError as E;
|
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
E::ParseInt(ParseIntError { source, .. })
|
Self::ParseInt(ParseIntError { source, .. })
|
||||||
if *source.kind() == IntErrorKind::PosOverflow =>
|
if *source.kind() == IntErrorKind::PosOverflow =>
|
||||||
None,
|
None,
|
||||||
E::ParseInt(ParseIntError { source, .. })
|
Self::ParseInt(ParseIntError { source, .. })
|
||||||
if *source.kind() == IntErrorKind::NegOverflow =>
|
if *source.kind() == IntErrorKind::NegOverflow =>
|
||||||
None,
|
None,
|
||||||
E::ParseInt(ParseIntError { source, .. }) => Some(source),
|
Self::ParseInt(ParseIntError { source, .. }) => Some(source),
|
||||||
E::Conversion(_) => None,
|
Self::Conversion(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue