From fb81bff61f7a447168932fd7e69b7067cc299d16 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 24 Jan 2024 13:31:57 +1100 Subject: [PATCH] Add a from impl for ParseIntError As is customary add a `From` impl for the `ParseIntError` and use `?`. While this does not make much difference it saves devs wondering why there is a `From` impl for one of the variants and not the other. --- bitcoin/src/blockdata/script/witness_version.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bitcoin/src/blockdata/script/witness_version.rs b/bitcoin/src/blockdata/script/witness_version.rs index 6897631f..05ee2846 100644 --- a/bitcoin/src/blockdata/script/witness_version.rs +++ b/bitcoin/src/blockdata/script/witness_version.rs @@ -87,7 +87,7 @@ impl FromStr for WitnessVersion { type Err = FromStrError; fn from_str(s: &str) -> Result { - 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 for FromStrError { + fn from(e: ParseIntError) -> Self { Self::Unparsable(e) } +} + impl From for FromStrError { fn from(e: TryFromError) -> Self { Self::Invalid(e) } }