expose error returned by impl of Num::from_str_radix

This commit is contained in:
Trevor Spiteri 2020-10-22 11:17:56 +02:00
parent db051272ca
commit 77a1e85504
2 changed files with 6 additions and 4 deletions

View File

@ -43,7 +43,7 @@ use num_traits::{
/// An error which can be returned when parsing a fixed-point number /// An error which can be returned when parsing a fixed-point number
/// with a given radix. /// with a given radix.
pub enum FixedFromStrRadixError { pub enum RadixParseFixedError {
/// The radix is not 2, 8, 10 or 16. /// The radix is not 2, 8, 10 or 16.
UnsupportedRadix, UnsupportedRadix,
/// The string could not be parsed as a fixed-point number. /// The string could not be parsed as a fixed-point number.
@ -88,7 +88,7 @@ macro_rules! impl_traits {
where where
Frac: IsLessOrEqual<$OneMaxFrac, Output = True>, Frac: IsLessOrEqual<$OneMaxFrac, Output = True>,
{ {
type FromStrRadixErr = FixedFromStrRadixError; type FromStrRadixErr = RadixParseFixedError;
#[inline] #[inline]
fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr> { fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr> {
@ -97,9 +97,9 @@ macro_rules! impl_traits {
8 => Self::from_str_octal(str), 8 => Self::from_str_octal(str),
10 => str.parse(), 10 => str.parse(),
16 => Self::from_str_hex(str), 16 => Self::from_str_hex(str),
_ => return Err(FixedFromStrRadixError::UnsupportedRadix), _ => return Err(RadixParseFixedError::UnsupportedRadix),
} }
.map_err(FixedFromStrRadixError::ParseFixedError) .map_err(RadixParseFixedError::ParseFixedError)
} }
} }

View File

@ -321,6 +321,8 @@ mod unwrapped;
mod wide_div; mod wide_div;
mod wrapping; mod wrapping;
#[cfg(feature = "num-traits")]
pub use crate::impl_num_traits::RadixParseFixedError;
#[cfg(feature = "unwrapped")] #[cfg(feature = "unwrapped")]
pub use crate::unwrapped::Unwrapped; pub use crate::unwrapped::Unwrapped;
use crate::{ use crate::{