rusty-numbers/src/lib.rs

44 lines
775 B
Rust
Raw Normal View History

2020-02-12 22:29:57 -05:00
#![forbid(unsafe_code)]
2020-02-12 23:10:08 -05:00
use std::ops::Not;
2020-02-12 22:29:57 -05:00
pub mod bigint;
pub mod rational;
pub mod seq;
/// Dummy trait for implementing generics on unsigned number types
2020-02-12 23:10:08 -05:00
pub trait Unsigned: PartialEq + PartialOrd {}
2020-02-12 22:29:57 -05:00
impl Unsigned for u8 {}
impl Unsigned for u16 {}
impl Unsigned for u32 {}
impl Unsigned for u64 {}
impl Unsigned for usize {}
impl Unsigned for u128 {}
2020-02-12 23:10:08 -05:00
#[derive(Debug, Copy, Clone)]
pub enum Sign {
Positive,
Negative
}
impl Not for Sign {
type Output = Sign;
fn not(self) -> Self::Output {
match self {
Self::Positive => Self::Negative,
Self::Negative => Self::Positive,
_ => unreachable!()
}
}
}
2020-02-12 22:29:57 -05:00
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}