Merge rust-bitcoin/rust-bitcoin#2395: Do minor error fixes

fb81bff61f Add a from impl for ParseIntError (Tobin C. Harding)
2130150df6 absolute: Use Self in error type (Tobin C. Harding)

Pull request description:

  While reviewing #2335 I noticed a few places that error code needed some love.

ACKs for top commit:
  Kixunil:
    ACK fb81bff61f
  Harshit933:
    ACK [`fb81bff`](fb81bff61f)
  apoelstra:
    ACK fb81bff61f

Tree-SHA512: 17f4e448862be47534d4c1c2962d5db8f90a471e53226022d7c2e153fc501705cd65b070eb17f3239fb8ad242223340f78fe828ea7df3d43707d3e42fcbef557
This commit is contained in:
Andrew Poelstra 2024-01-24 22:06:52 +00:00
commit 48b42c10fb
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
2 changed files with 8 additions and 4 deletions

View File

@ -587,17 +587,17 @@ impl std::error::Error for Error {
impl From<ConversionError> for Error {
#[inline]
fn from(e: ConversionError) -> Self { Error::Conversion(e) }
fn from(e: ConversionError) -> Self { Self::Conversion(e) }
}
impl From<OperationError> for Error {
#[inline]
fn from(e: OperationError) -> Self { Error::Operation(e) }
fn from(e: OperationError) -> Self { Self::Operation(e) }
}
impl From<ParseIntError> for Error {
#[inline]
fn from(e: ParseIntError) -> Self { Error::Parse(e) }
fn from(e: ParseIntError) -> Self { Self::Parse(e) }
}
/// An error that occurs when converting a `u32` to a lock time variant.

View File

@ -87,7 +87,7 @@ impl FromStr for WitnessVersion {
type Err = FromStrError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let version: u8 = crate::parse::int(s).map_err(FromStrError::Unparsable)?;
let version: u8 = crate::parse::int(s)?;
Ok(WitnessVersion::try_from(version)?)
}
}
@ -198,6 +198,10 @@ impl std::error::Error for FromStrError {
}
}
impl From<ParseIntError> for FromStrError {
fn from(e: ParseIntError) -> Self { Self::Unparsable(e) }
}
impl From<TryFromError> for FromStrError {
fn from(e: TryFromError) -> Self { Self::Invalid(e) }
}