Files
sigils/src/natural.rs

33 lines
912 B
Rust
Raw Normal View History

// SPDX-License-Identifier: Apache-2.0
// Sealed with Magistamp.
use core::mem::size_of;
use core::ops::{Add, Sub, Mul, Div, Rem};
use core::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign};
use core::str::FromStr;
use crate::number::Number;
use crate::one::One;
/// A Natural number is a counting number from one to infinity.
/// 1, 2, 3, 4, 5, 6, ...
///
/// Rust types that are in this category are:
/// u8, u16, u32, u64, u128, usize
pub trait Natural: Number + One +
Add<Output=Self> + AddAssign +
Sub<Output=Self> + SubAssign +
Mul<Output=Self> + MulAssign +
Div<Output=Self> + DivAssign +
Rem<Output=Self> + RemAssign
{
/// Performs division and returns both the quotient and remainder.
#[inline]
fn div_rem(self, rhs: Self) -> (Self, Self)
{
(self / rhs, self % rhs)
}
}