pub trait Num:
PartialEq
+ Zero
+ One
+ NumOps {
type FromStrRadixErr;
// Required method
fn from_str_radix(
str: &str,
radix: u32,
) -> Result<Self, Self::FromStrRadixErr>;
}
Expand description
The base trait for numeric types, covering 0
and 1
values,
comparisons, basic numeric operations, and string conversion.
Required Associated Types§
Required Methods§
Sourcefn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
Convert from a string and radix <= 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());
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.