Merge rust-bitcoin/rust-bitcoin#3842: Remove usage of impl_from_infallible in leaf crates
0d8e9ef096
Remove usage of impl_from_infallible in leaf crates (Tobin C. Harding)
Pull request description:
Rust macros, while at times useful, are a maintenance nightmare. And we have been bitten by calling macros from other crates multiple times in the past.
In a push to just use less macros remove the usage of the `impl_from_infallible` macro in all the leaf crates and just write the code.
ACKs for top commit:
apoelstra:
ACK 0d8e9ef096fd60fcdb7928697c8f554bf428b754; successfully ran local tests; this is a great change
Tree-SHA512: c4cff4517f7846d91142f26d451c2bcafc014a0921d11ac1487eab087449f12023c3b4fc57e1bc72ed3ea58406b4c3d24bbd846df21353f5d7ecb4a4b8bfb0b2
This commit is contained in:
commit
dddb63f4ad
|
@ -2,13 +2,16 @@
|
|||
|
||||
//! Error code for the `hashes` crate.
|
||||
|
||||
use core::convert::Infallible;
|
||||
use core::fmt;
|
||||
|
||||
/// Attempted to create a hash from an invalid length slice.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct FromSliceError(pub(crate) FromSliceErrorInner);
|
||||
|
||||
impl_from_infallible!(FromSliceError);
|
||||
impl From<Infallible> for FromSliceError {
|
||||
fn from(never: Infallible) -> Self { match never {} }
|
||||
}
|
||||
|
||||
impl FromSliceError {
|
||||
/// Returns the expected slice length.
|
||||
|
@ -25,7 +28,9 @@ pub(crate) struct FromSliceErrorInner {
|
|||
pub(crate) got: usize,
|
||||
}
|
||||
|
||||
impl_from_infallible!(FromSliceErrorInner);
|
||||
impl From<Infallible> for FromSliceErrorInner {
|
||||
fn from(never: Infallible) -> Self { match never {} }
|
||||
}
|
||||
|
||||
impl fmt::Display for FromSliceError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
|
@ -35,19 +40,3 @@ impl fmt::Display for FromSliceError {
|
|||
|
||||
#[cfg(feature = "std")]
|
||||
impl std::error::Error for FromSliceError {}
|
||||
|
||||
/// Derives `From<core::convert::Infallible>` for the given type.
|
||||
// This is a duplicate of `internals::impl_from_infallible`, see there for complete docs.
|
||||
#[doc(hidden)]
|
||||
macro_rules! impl_from_infallible {
|
||||
( $name:ident $(< $( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? ) => {
|
||||
impl $(< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)?
|
||||
From<core::convert::Infallible>
|
||||
for $name
|
||||
$(< $( $lt ),+ >)?
|
||||
{
|
||||
fn from(never: core::convert::Infallible) -> Self { match never {} }
|
||||
}
|
||||
}
|
||||
}
|
||||
pub(crate) use impl_from_infallible;
|
||||
|
|
|
@ -8,6 +8,7 @@ mod borrowed;
|
|||
mod owned;
|
||||
|
||||
use core::cmp::Ordering;
|
||||
use core::convert::Infallible;
|
||||
use core::fmt;
|
||||
use core::ops::{Deref, DerefMut};
|
||||
|
||||
|
@ -158,7 +159,9 @@ pub struct RedeemScriptSizeError {
|
|||
pub size: usize,
|
||||
}
|
||||
|
||||
internals::impl_from_infallible!(RedeemScriptSizeError);
|
||||
impl From<Infallible> for RedeemScriptSizeError {
|
||||
fn from(never: Infallible) -> Self { match never {} }
|
||||
}
|
||||
|
||||
impl fmt::Display for RedeemScriptSizeError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
|
@ -176,7 +179,9 @@ pub struct WitnessScriptSizeError {
|
|||
pub size: usize,
|
||||
}
|
||||
|
||||
internals::impl_from_infallible!(WitnessScriptSizeError);
|
||||
impl From<Infallible> for WitnessScriptSizeError {
|
||||
fn from(never: Infallible) -> Self { match never {} }
|
||||
}
|
||||
|
||||
impl fmt::Display for WitnessScriptSizeError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
#[cfg(feature = "alloc")]
|
||||
use core::cmp;
|
||||
use core::convert::Infallible;
|
||||
use core::fmt;
|
||||
|
||||
#[cfg(feature = "arbitrary")]
|
||||
|
@ -444,7 +445,9 @@ pub enum ParseOutPointError {
|
|||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
internals::impl_from_infallible!(ParseOutPointError);
|
||||
impl From<Infallible> for ParseOutPointError {
|
||||
fn from(never: Infallible) -> Self { match never {} }
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl fmt::Display for ParseOutPointError {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
//! Error types for bitcoin amounts.
|
||||
|
||||
use core::convert::Infallible;
|
||||
use core::fmt;
|
||||
|
||||
use internals::error::InputString;
|
||||
|
@ -23,8 +24,13 @@ pub(crate) enum ParseErrorInner {
|
|||
MissingDenomination(MissingDenominationError),
|
||||
}
|
||||
|
||||
internals::impl_from_infallible!(ParseError);
|
||||
internals::impl_from_infallible!(ParseErrorInner);
|
||||
impl From<Infallible> for ParseError {
|
||||
fn from(never: Infallible) -> Self { match never {} }
|
||||
}
|
||||
|
||||
impl From<Infallible> for ParseErrorInner {
|
||||
fn from(never: Infallible) -> Self { match never {} }
|
||||
}
|
||||
|
||||
impl From<ParseAmountError> for ParseError {
|
||||
fn from(e: ParseAmountError) -> Self { Self(ParseErrorInner::Amount(e)) }
|
||||
|
@ -114,8 +120,13 @@ impl From<InvalidCharacterError> for ParseAmountError {
|
|||
}
|
||||
}
|
||||
|
||||
internals::impl_from_infallible!(ParseAmountError);
|
||||
internals::impl_from_infallible!(ParseAmountErrorInner);
|
||||
impl From<Infallible> for ParseAmountError {
|
||||
fn from(never: Infallible) -> Self { match never {} }
|
||||
}
|
||||
|
||||
impl From<Infallible> for ParseAmountErrorInner {
|
||||
fn from(never: Infallible) -> Self { match never {} }
|
||||
}
|
||||
|
||||
impl fmt::Display for ParseAmountError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
|
@ -318,7 +329,9 @@ pub enum ParseDenominationError {
|
|||
PossiblyConfusing(PossiblyConfusingDenominationError),
|
||||
}
|
||||
|
||||
internals::impl_from_infallible!(ParseDenominationError);
|
||||
impl From<Infallible> for ParseDenominationError {
|
||||
fn from(never: Infallible) -> Self { match never {} }
|
||||
}
|
||||
|
||||
impl fmt::Display for ParseDenominationError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
|
|
|
@ -17,6 +17,7 @@ mod unsigned;
|
|||
mod verification;
|
||||
|
||||
use core::cmp::Ordering;
|
||||
use core::convert::Infallible;
|
||||
use core::fmt;
|
||||
use core::str::FromStr;
|
||||
|
||||
|
@ -292,7 +293,9 @@ enum InnerParseError {
|
|||
InvalidCharacter(InvalidCharacterError),
|
||||
}
|
||||
|
||||
internals::impl_from_infallible!(InnerParseError);
|
||||
impl From<Infallible> for InnerParseError {
|
||||
fn from(never: Infallible) -> Self { match never {} }
|
||||
}
|
||||
|
||||
impl InnerParseError {
|
||||
fn convert(self, is_signed: bool) -> ParseAmountError {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
//! Provides [`Height`] and [`Time`] types used by the `rust-bitcoin` `absolute::LockTime` type.
|
||||
|
||||
use core::convert::Infallible;
|
||||
use core::fmt;
|
||||
|
||||
#[cfg(feature = "arbitrary")]
|
||||
|
@ -307,7 +308,9 @@ enum ParseError {
|
|||
Conversion(i64),
|
||||
}
|
||||
|
||||
internals::impl_from_infallible!(ParseError);
|
||||
impl From<Infallible> for ParseError {
|
||||
fn from(never: Infallible) -> Self { match never {} }
|
||||
}
|
||||
|
||||
impl ParseError {
|
||||
fn invalid_int<S: Into<InputString>>(s: S) -> impl FnOnce(core::num::ParseIntError) -> Self {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
//! Parsing utilities.
|
||||
|
||||
use core::convert::Infallible;
|
||||
use core::fmt;
|
||||
use core::str::FromStr;
|
||||
|
||||
|
@ -355,8 +356,13 @@ enum PrefixedHexErrorInner {
|
|||
ParseInt(ParseIntError),
|
||||
}
|
||||
|
||||
internals::impl_from_infallible!(PrefixedHexError);
|
||||
internals::impl_from_infallible!(PrefixedHexErrorInner);
|
||||
impl From<Infallible> for PrefixedHexError {
|
||||
fn from(never: Infallible) -> Self { match never {} }
|
||||
}
|
||||
|
||||
impl From<Infallible> for PrefixedHexErrorInner {
|
||||
fn from(never: Infallible) -> Self { match never {} }
|
||||
}
|
||||
|
||||
impl fmt::Display for PrefixedHexError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
|
@ -401,8 +407,13 @@ enum UnprefixedHexErrorInner {
|
|||
ParseInt(ParseIntError),
|
||||
}
|
||||
|
||||
internals::impl_from_infallible!(UnprefixedHexError);
|
||||
internals::impl_from_infallible!(UnprefixedHexErrorInner);
|
||||
impl From<Infallible> for UnprefixedHexError {
|
||||
fn from(never: Infallible) -> Self { match never {} }
|
||||
}
|
||||
|
||||
impl From<Infallible> for UnprefixedHexErrorInner {
|
||||
fn from(never: Infallible) -> Self { match never {} }
|
||||
}
|
||||
|
||||
impl fmt::Display for UnprefixedHexError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
|
|
Loading…
Reference in New Issue