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.
This commit is contained in:
Tobin C. Harding 2024-01-24 13:31:57 +11:00
parent 2130150df6
commit fb81bff61f
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 5 additions and 1 deletions

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) }
}