Trait num::traits::Num [−][src]
The base trait for numeric types, covering 0
and 1
values,
comparisons, basic numeric operations, and string conversion.
Associated Types
type FromStrRadixErr
[src]
Required methods
pub fn from_str_radix(
str: &str,
radix: u32
) -> Result<Self, Self::FromStrRadixErr>
[src]
str: &str,
radix: u32
) -> Result<Self, Self::FromStrRadixErr>
Convert from a string and radix (typically 2..=36
).
Examples
use num_traits::Num; let result = <i32 as Num>::from_str_radix("27", 10); assert_eq!(result, Ok(27)); let result = <i32 as Num>::from_str_radix("foo", 10); assert!(result.is_err());
Supported radices
The exact range of supported radices is at the discretion of each type implementation. For
primitive integers, this is implemented by the inherent from_str_radix
methods in the
standard library, which panic if the radix is not in the range from 2 to 36. The
implementation in this crate for primitive floats is similar.
For third-party types, it is suggested that implementations should follow suit and at least
accept 2..=36
without panicking, but an Err
may be returned for any unsupported radix.
It’s possible that a type might not even support the common radix 10, nor any, if string
parsing doesn’t make sense for that type.
Implementations on Foreign Types
impl Num for u16
[src]
type FromStrRadixErr = ParseIntError
pub fn from_str_radix(s: &str, radix: u32) -> Result<u16, ParseIntError>
[src]
impl Num for isize
[src]
type FromStrRadixErr = ParseIntError
pub fn from_str_radix(s: &str, radix: u32) -> Result<isize, ParseIntError>
[src]
impl Num for u32
[src]
type FromStrRadixErr = ParseIntError
pub fn from_str_radix(s: &str, radix: u32) -> Result<u32, ParseIntError>
[src]
impl Num for u128
[src]
type FromStrRadixErr = ParseIntError
pub fn from_str_radix(s: &str, radix: u32) -> Result<u128, ParseIntError>
[src]
impl<T> Num for Wrapping<T> where
T: Num,
Wrapping<T>: Mul<Wrapping<T>>,
Wrapping<T>: Add<Wrapping<T>>,
Wrapping<T>: Div<Wrapping<T>>,
Wrapping<T>: Rem<Wrapping<T>>,
Wrapping<T>: Sub<Wrapping<T>>,
<Wrapping<T> as Add<Wrapping<T>>>::Output == Wrapping<T>,
<Wrapping<T> as Sub<Wrapping<T>>>::Output == Wrapping<T>,
<Wrapping<T> as Mul<Wrapping<T>>>::Output == Wrapping<T>,
<Wrapping<T> as Div<Wrapping<T>>>::Output == Wrapping<T>,
<Wrapping<T> as Rem<Wrapping<T>>>::Output == Wrapping<T>,
[src]
T: Num,
Wrapping<T>: Mul<Wrapping<T>>,
Wrapping<T>: Add<Wrapping<T>>,
Wrapping<T>: Div<Wrapping<T>>,
Wrapping<T>: Rem<Wrapping<T>>,
Wrapping<T>: Sub<Wrapping<T>>,
<Wrapping<T> as Add<Wrapping<T>>>::Output == Wrapping<T>,
<Wrapping<T> as Sub<Wrapping<T>>>::Output == Wrapping<T>,
<Wrapping<T> as Mul<Wrapping<T>>>::Output == Wrapping<T>,
<Wrapping<T> as Div<Wrapping<T>>>::Output == Wrapping<T>,
<Wrapping<T> as Rem<Wrapping<T>>>::Output == Wrapping<T>,
type FromStrRadixErr = <T as Num>::FromStrRadixErr
pub fn from_str_radix(
str: &str,
radix: u32
) -> Result<Wrapping<T>, <Wrapping<T> as Num>::FromStrRadixErr>
[src]
str: &str,
radix: u32
) -> Result<Wrapping<T>, <Wrapping<T> as Num>::FromStrRadixErr>
impl Num for i16
[src]
type FromStrRadixErr = ParseIntError
pub fn from_str_radix(s: &str, radix: u32) -> Result<i16, ParseIntError>
[src]
impl Num for f64
[src]
type FromStrRadixErr = ParseFloatError
pub fn from_str_radix(
src: &str,
radix: u32
) -> Result<f64, <f64 as Num>::FromStrRadixErr>
[src]
src: &str,
radix: u32
) -> Result<f64, <f64 as Num>::FromStrRadixErr>
impl Num for u64
[src]
type FromStrRadixErr = ParseIntError
pub fn from_str_radix(s: &str, radix: u32) -> Result<u64, ParseIntError>
[src]
impl Num for u8
[src]
type FromStrRadixErr = ParseIntError
pub fn from_str_radix(s: &str, radix: u32) -> Result<u8, ParseIntError>
[src]
impl Num for i8
[src]
type FromStrRadixErr = ParseIntError
pub fn from_str_radix(s: &str, radix: u32) -> Result<i8, ParseIntError>
[src]
impl Num for i64
[src]
type FromStrRadixErr = ParseIntError
pub fn from_str_radix(s: &str, radix: u32) -> Result<i64, ParseIntError>
[src]
impl Num for i32
[src]
type FromStrRadixErr = ParseIntError
pub fn from_str_radix(s: &str, radix: u32) -> Result<i32, ParseIntError>
[src]
impl Num for i128
[src]
type FromStrRadixErr = ParseIntError
pub fn from_str_radix(s: &str, radix: u32) -> Result<i128, ParseIntError>
[src]
impl Num for f32
[src]
type FromStrRadixErr = ParseFloatError
pub fn from_str_radix(
src: &str,
radix: u32
) -> Result<f32, <f32 as Num>::FromStrRadixErr>
[src]
src: &str,
radix: u32
) -> Result<f32, <f32 as Num>::FromStrRadixErr>
impl Num for usize
[src]
type FromStrRadixErr = ParseIntError
pub fn from_str_radix(s: &str, radix: u32) -> Result<usize, ParseIntError>
[src]
Implementors
impl Num for BigInt
[src]
type FromStrRadixErr = ParseBigIntError
pub fn from_str_radix(s: &str, radix: u32) -> Result<BigInt, ParseBigIntError>
[src]
Creates and initializes a BigInt.
impl Num for BigUint
[src]
type FromStrRadixErr = ParseBigIntError
pub fn from_str_radix(s: &str, radix: u32) -> Result<BigUint, ParseBigIntError>
[src]
Creates and initializes a BigUint
.
impl<T> Num for Ratio<T> where
T: Clone + Integer,
[src]
T: Clone + Integer,
type FromStrRadixErr = ParseRatioError
pub fn from_str_radix(s: &str, radix: u32) -> Result<Ratio<T>, ParseRatioError>
[src]
Parses numer/denom
where the numbers are in base radix
.
impl<T> Num for Complex<T> where
T: Num + Clone,
[src]
T: Num + Clone,
type FromStrRadixErr = ParseComplexError<<T as Num>::FromStrRadixErr>
pub fn from_str_radix(
s: &str,
radix: u32
) -> Result<Complex<T>, <Complex<T> as Num>::FromStrRadixErr>
[src]
s: &str,
radix: u32
) -> Result<Complex<T>, <Complex<T> as Num>::FromStrRadixErr>
Parses a +/- bi
; ai +/- b
; a
; or bi
where a
and b
are of type T