pub trait NumberBase:
Clone
+ Eq
+ Hash
+ PartialOrd {
// Required methods
fn zero() -> Self;
fn one() -> Self;
fn nan() -> Self;
fn add(&self, rhs: &Self) -> Self;
fn sub(&self, rhs: &Self) -> Self;
fn mul(&self, rhs: &Self) -> Self;
fn div(&self, rhs: &Self) -> Self;
// Provided methods
fn is_zero(&self) -> bool { ... }
fn is_one(&self) -> bool { ... }
fn is_nan(&self) -> bool { ... }
}
Expand description
Basic trait for numbers
zero()
, one()
, and nan()
are
implemented as functions because depending on the number underlying type,
it can be hard/impossible to obtain a const
for these values.
This trait also includes basic arithmetic methods. This is to avoid cloning
of big integers. We could also require &Self: Add<&Self, Output = Self>
etc., but this would lead to ugly trait bounds.
Used by PseudoBooleanFunction::Number
Required Methods§
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.