pub trait Num {
type Inner;
type Out;
type Rhs;
Show 30 methods
// Required method
fn num_into(self) -> Self::Inner;
// Provided methods
fn num_from(value: Self::Inner) -> Result<Self>
where Self: Sized { ... }
fn num_from_ref(value: &Self::Inner) -> Result<Self>
where Self: Sized { ... }
fn num_set(&mut self, value: Self::Inner) -> Result<()> { ... }
fn num_set_ref(&mut self, value: &Self::Inner) -> Result<()> { ... }
fn num_is_zero(&self) -> Result<bool> { ... }
fn num_get_zero() -> Result<Self>
where Self: Sized { ... }
fn num_set_zero(&mut self) -> Result<()> { ... }
fn num_is_one(&self) -> Result<bool> { ... }
fn num_get_one() -> Result<Self>
where Self: Sized { ... }
fn num_set_one(&mut self) -> Result<()> { ... }
fn num_add(self, rhs: Self::Rhs) -> Result<Self::Out>
where Self: Sized { ... }
fn num_ref_add(&self, rhs: &Self::Rhs) -> Result<Self::Out> { ... }
fn num_ref_add_assign(&mut self, rhs: &Self::Rhs) -> Result<()> { ... }
fn num_sub(self, rhs: Self::Rhs) -> Result<Self::Out>
where Self: Sized { ... }
fn num_ref_sub(&self, rhs: &Self::Rhs) -> Result<Self::Out> { ... }
fn num_ref_sub_assign(&mut self, rhs: &Self::Rhs) -> Result<()> { ... }
fn num_mul(self, rhs: Self::Rhs) -> Result<Self::Out>
where Self: Sized { ... }
fn num_ref_mul(&self, rhs: &Self::Rhs) -> Result<Self::Out> { ... }
fn num_ref_mul_assign(&mut self, rhs: &Self::Rhs) -> Result<()> { ... }
fn num_div(self, rhs: Self::Rhs) -> Result<Self::Out>
where Self: Sized { ... }
fn num_ref_div(&self, rhs: &Self::Rhs) -> Result<Self::Out> { ... }
fn num_ref_div_assign(&mut self, rhs: &Self::Rhs) -> Result<()> { ... }
fn num_rem(self, rhs: Self::Rhs) -> Result<Self::Out>
where Self: Sized { ... }
fn num_ref_rem(&self, rhs: &Self::Rhs) -> Result<Self::Out> { ... }
fn num_ref_rem_assign(&mut self, rhs: &Self::Rhs) -> Result<()> { ... }
fn num_neg(self) -> Result<Self::Out>
where Self: Sized { ... }
fn num_ref_neg(&self) -> Result<Self::Out> { ... }
fn num_abs(self) -> Result<Self::Out>
where Self: Sized { ... }
fn num_ref_abs(&self) -> Result<Self::Out> { ... }
}
Expand description
Common trait for numeric types.
§Notes
-
Every method has a default implementation that returns
NotImplemented
. -
Specific implementations can customize the operations it wants to support.
-
Any operations specifically not supported should ideally return
NotSupported
. -
Most methods come in two variants, starting with different prefixes:
num_*
methods take the arguments by value.num_ref_*
methods take the arguments by reference.
-
This trait tries to offer the same methods everywhere, giving a result when possible.
-
Operations are generally supported if they can be valid for some values. E.g.
num_abs
for unsigned types is only valid for0
.
See also NumRef
which is automatically implemented for Num
references.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn num_from(value: Self::Inner) -> Result<Self>where
Self: Sized,
fn num_from(value: Self::Inner) -> Result<Self>where
Self: Sized,
Returns Self
if given a valid value
.
Sourcefn num_from_ref(value: &Self::Inner) -> Result<Self>where
Self: Sized,
fn num_from_ref(value: &Self::Inner) -> Result<Self>where
Self: Sized,
Returns Self
if given a valid &value
.
Sourcefn num_set_ref(&mut self, value: &Self::Inner) -> Result<()>
fn num_set_ref(&mut self, value: &Self::Inner) -> Result<()>
Sets self
to the given valid &value
.
Sourcefn num_is_zero(&self) -> Result<bool>
fn num_is_zero(&self) -> Result<bool>
Returns true
if self
is zero.
Sourcefn num_get_zero() -> Result<Self>where
Self: Sized,
fn num_get_zero() -> Result<Self>where
Self: Sized,
Returns the number zero.
Sourcefn num_set_zero(&mut self) -> Result<()>
fn num_set_zero(&mut self) -> Result<()>
Sets self
to 0
.
Sourcefn num_is_one(&self) -> Result<bool>
fn num_is_one(&self) -> Result<bool>
Returns true
if self
is one.
Sourcefn num_get_one() -> Result<Self>where
Self: Sized,
fn num_get_one() -> Result<Self>where
Self: Sized,
Returns the number one.
Sourcefn num_set_one(&mut self) -> Result<()>
fn num_set_one(&mut self) -> Result<()>
Sets the number to one.
Sourcefn num_add(self, rhs: Self::Rhs) -> Result<Self::Out>where
Self: Sized,
fn num_add(self, rhs: Self::Rhs) -> Result<Self::Out>where
Self: Sized,
Computes self + rhs
(addition).
Sourcefn num_ref_add(&self, rhs: &Self::Rhs) -> Result<Self::Out>
fn num_ref_add(&self, rhs: &Self::Rhs) -> Result<Self::Out>
Like num_add
but takes the arguments by reference.
Sourcefn num_ref_add_assign(&mut self, rhs: &Self::Rhs) -> Result<()>
fn num_ref_add_assign(&mut self, rhs: &Self::Rhs) -> Result<()>
Computes &mut self += rhs;
(addition).
Sourcefn num_sub(self, rhs: Self::Rhs) -> Result<Self::Out>where
Self: Sized,
fn num_sub(self, rhs: Self::Rhs) -> Result<Self::Out>where
Self: Sized,
Computes self - rhs
(subtraction).
Sourcefn num_ref_sub(&self, rhs: &Self::Rhs) -> Result<Self::Out>
fn num_ref_sub(&self, rhs: &Self::Rhs) -> Result<Self::Out>
Like num_sub
but takes the arguments by reference.
Sourcefn num_ref_sub_assign(&mut self, rhs: &Self::Rhs) -> Result<()>
fn num_ref_sub_assign(&mut self, rhs: &Self::Rhs) -> Result<()>
Computes &mut self -= rhs;
(subtraction).
Sourcefn num_mul(self, rhs: Self::Rhs) -> Result<Self::Out>where
Self: Sized,
fn num_mul(self, rhs: Self::Rhs) -> Result<Self::Out>where
Self: Sized,
Computes self * rhs
(multiplication).
Sourcefn num_ref_mul(&self, rhs: &Self::Rhs) -> Result<Self::Out>
fn num_ref_mul(&self, rhs: &Self::Rhs) -> Result<Self::Out>
Like num_mul
but takes the arguments by reference.
Sourcefn num_ref_mul_assign(&mut self, rhs: &Self::Rhs) -> Result<()>
fn num_ref_mul_assign(&mut self, rhs: &Self::Rhs) -> Result<()>
Computes &mut self *= rhs;
(multiplication).
Sourcefn num_div(self, rhs: Self::Rhs) -> Result<Self::Out>where
Self: Sized,
fn num_div(self, rhs: Self::Rhs) -> Result<Self::Out>where
Self: Sized,
Computes self / rhs
(division).
Sourcefn num_ref_div(&self, rhs: &Self::Rhs) -> Result<Self::Out>
fn num_ref_div(&self, rhs: &Self::Rhs) -> Result<Self::Out>
Like num_div
but takes the arguments by reference.
Sourcefn num_ref_div_assign(&mut self, rhs: &Self::Rhs) -> Result<()>
fn num_ref_div_assign(&mut self, rhs: &Self::Rhs) -> Result<()>
Computes &mut self /= rhs;
(division).
Sourcefn num_rem(self, rhs: Self::Rhs) -> Result<Self::Out>where
Self: Sized,
fn num_rem(self, rhs: Self::Rhs) -> Result<Self::Out>where
Self: Sized,
Computes self % rhs
(remainder).
Sourcefn num_ref_rem(&self, rhs: &Self::Rhs) -> Result<Self::Out>
fn num_ref_rem(&self, rhs: &Self::Rhs) -> Result<Self::Out>
Like num_rem
but takes the arguments by reference.
Sourcefn num_ref_rem_assign(&mut self, rhs: &Self::Rhs) -> Result<()>
fn num_ref_rem_assign(&mut self, rhs: &Self::Rhs) -> Result<()>
Computes &mut self %= rhs;
(remainder).
Sourcefn num_ref_neg(&self) -> Result<Self::Out>
fn num_ref_neg(&self) -> Result<Self::Out>
Like num_neg
but takes the arguments by reference.
Sourcefn num_ref_abs(&self) -> Result<Self::Out>
fn num_ref_abs(&self) -> Result<Self::Out>
Like num_abs
but takes the arguments by reference.
Implementations on Foreign Types§
Source§impl Num for f64
Available on crate feature _float_f64
only.
impl Num for f64
_float_f64
only.type Inner = f64
type Out = f64
type Rhs = f64
fn num_into(self) -> Self::Inner
fn num_from(from: Self::Inner) -> Result<Self>
fn num_from_ref(from: &Self::Inner) -> Result<Self>
fn num_set(&mut self, value: Self::Inner) -> Result<()>
fn num_set_ref(&mut self, value: &Self::Inner) -> Result<()>
fn num_get_zero() -> Result<Self>
fn num_get_one() -> Result<Self>
fn num_set_zero(&mut self) -> Result<()>
fn num_set_one(&mut self) -> Result<()>
fn num_add(self, other: Self) -> Result<Self::Out>
fn num_ref_add(&self, other: &Self) -> Result<Self::Out>
fn num_mul(self, other: Self) -> Result<Self::Out>
fn num_ref_mul(&self, other: &Self) -> Result<Self::Out>
fn num_sub(self, other: Self) -> Result<Self::Out>
fn num_ref_sub(&self, other: &Self) -> Result<Self::Out>
fn num_div(self, other: Self) -> Result<Self::Out>
fn num_ref_div(&self, other: &Self) -> Result<Self::Out>
fn num_rem(self, other: Self) -> Result<Self::Out>
fn num_ref_rem(&self, other: &Self) -> Result<Self::Out>
fn num_neg(self) -> Result<Self::Out>
fn num_ref_neg(&self) -> Result<Self::Out>
fn num_abs(self) -> Result<Self>
fn num_ref_abs(&self) -> Result<Self>
Source§impl Num for i64
Available on crate feature _int_i64
only.
impl Num for i64
_int_i64
only.type Inner = i64
type Out = i64
type Rhs = i64
fn num_into(self) -> Self::Inner
fn num_from(from: Self::Inner) -> Result<Self>
fn num_from_ref(from: &Self::Inner) -> Result<Self>
fn num_set(&mut self, value: Self::Inner) -> Result<()>
fn num_set_ref(&mut self, value: &Self::Inner) -> Result<()>
fn num_is_zero(&self) -> Result<bool>
fn num_is_one(&self) -> Result<bool>
fn num_get_zero() -> Result<Self>
fn num_get_one() -> Result<Self>
fn num_set_zero(&mut self) -> Result<()>
fn num_set_one(&mut self) -> Result<()>
fn num_add(self, other: Self) -> Result<Self::Out>
fn num_ref_add(&self, other: &Self) -> Result<Self::Out>
fn num_ref_add_assign(&mut self, other: &Self) -> Result<()>
fn num_mul(self, other: Self) -> Result<Self::Out>
fn num_ref_mul(&self, other: &Self) -> Result<Self::Out>
fn num_ref_mul_assign(&mut self, other: &Self) -> Result<()>
fn num_sub(self, other: Self) -> Result<Self::Out>
fn num_ref_sub(&self, other: &Self) -> Result<Self::Out>
fn num_ref_sub_assign(&mut self, other: &Self) -> Result<()>
fn num_div(self, other: Self) -> Result<Self::Out>
fn num_ref_div(&self, other: &Self) -> Result<Self::Out>
fn num_ref_div_assign(&mut self, other: &Self) -> Result<()>
fn num_rem(self, other: Self) -> Result<Self::Out>
fn num_ref_rem(&self, other: &Self) -> Result<Self::Out>
fn num_ref_rem_assign(&mut self, other: &Self) -> Result<()>
fn num_neg(self) -> Result<Self::Out>
fn num_ref_neg(&self) -> Result<Self::Out>
fn num_abs(self) -> Result<Self::Out>
fn num_ref_abs(&self) -> Result<Self::Out>
Source§impl Num for u32
Available on crate feature _int_u32
only.
impl Num for u32
_int_u32
only.