pub trait Numeric:
Copy
+ PartialOrd
+ Debug
+ Display {
const MAX: Self;
const ZERO: Self;
const ONE: Self;
// Required methods
fn abs(self) -> Self;
fn clamp(self, min: Self, max: Self) -> Self;
fn checked_sub(self, other: Self) -> Option<Self>;
fn checked_add(self, other: Self) -> Option<Self>;
fn checked_mul(self, other: Self) -> Option<Self>;
fn checked_div(self, other: Self) -> Option<Self>;
fn from_usize(value: usize) -> Option<Self>;
fn into_f64(self) -> f64;
fn from_f64(value: f64) -> Option<Self>;
// Provided methods
fn abs_diff(self, other: Self) -> Self { ... }
fn scale(self, factor: impl Numeric) -> Option<Self> { ... }
}Expand description
Represents a numeric type that can be interpolated across By default, implemented for:
f32f64i8i16i32i64i128isizeu8u16u32u64u128usize
Required Associated Constants§
Required Methods§
Sourcefn clamp(self, min: Self, max: Self) -> Self
fn clamp(self, min: Self, max: Self) -> Self
Clamp this number between a minimum and maximum value.
Differs from std::cmp::Ord::clamp in that it must handle cases where min > max
Sourcefn checked_sub(self, other: Self) -> Option<Self>
fn checked_sub(self, other: Self) -> Option<Self>
Subtract another number from this one, returning None if the operation would overflow
Sourcefn checked_add(self, other: Self) -> Option<Self>
fn checked_add(self, other: Self) -> Option<Self>
Add two numbers together, returning None if the operation would overflow
Sourcefn checked_mul(self, other: Self) -> Option<Self>
fn checked_mul(self, other: Self) -> Option<Self>
Multiply two numbers together, returning None if the operation would overflow
Sourcefn checked_div(self, other: Self) -> Option<Self>
fn checked_div(self, other: Self) -> Option<Self>
Divide two numbers, returning None if the operation would overflow
Sourcefn from_usize(value: usize) -> Option<Self>
fn from_usize(value: usize) -> Option<Self>
Convert a usize to this type
Provided Methods§
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.