There is still some work to do with defining integers and whole numbers better, but for now the library is usable and reasonably tested.
47 lines
1.6 KiB
Rust
47 lines
1.6 KiB
Rust
use super::number::Number;
|
|
|
|
|
|
/// A trait that defines what is required to be considered
|
|
/// an Integer. [List of types of numbers][1]
|
|
///
|
|
/// This is meant to have all the similarities between
|
|
/// [u8][2], [u16][3], [u32][4], [u64][5], [usize][6],
|
|
/// [i8][7], [i16][8], [i32][9], [i64][10], [isize][11].
|
|
/// Most of the comments and documentation were taken
|
|
/// from the [rust-lang std docs][12].
|
|
///
|
|
/// [1]: https://en.wikipedia.org/wiki/List_of_types_of_numbers
|
|
/// [2]: https://doc.rust-lang.org/std/primitive.u8.html
|
|
/// [3]: https://doc.rust-lang.org/std/primitive.u16.html
|
|
/// [4]: https://doc.rust-lang.org/std/primitive.u32.html
|
|
/// [5]: https://doc.rust-lang.org/std/primitive.u64.html
|
|
/// [6]: https://doc.rust-lang.org/std/primitive.usize.html
|
|
/// [7]: https://doc.rust-lang.org/std/primitive.i8.html
|
|
/// [8]: https://doc.rust-lang.org/std/primitive.i16.html
|
|
/// [9]: https://doc.rust-lang.org/std/primitive.i32.html
|
|
/// [10]: https://doc.rust-lang.org/std/primitive.i64.html
|
|
/// [11]: https://doc.rust-lang.org/std/primitive.isize.html
|
|
/// [12]: https://doc.rust-lang.org/std/index.html
|
|
pub trait Integer : Number
|
|
{
|
|
}
|
|
|
|
|
|
// Create a macro to ease typing and reading.
|
|
/// A macro to make implementing the trait easier for all the
|
|
/// base integer types in rust.
|
|
macro_rules! integer_trait_impl
|
|
{
|
|
($traitName: ident for $($varType: ty)*) =>
|
|
($(
|
|
impl $traitName for $varType
|
|
{
|
|
}
|
|
)*)
|
|
}
|
|
|
|
|
|
// Implement the trait for the types that are Integers.
|
|
integer_trait_impl!(Integer for u8 u16 u32 u64 usize);
|
|
integer_trait_impl!(Integer for i8 i16 i32 i64 isize);
|