1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
mod cast;
mod max;
mod min;

pub use self::{cast::*, max::Max, min::Min};
pub use num_traits;

use std::fmt::Debug;

pub trait Num:
    Copy + Debug + Max + Min + num_traits::Num + num_traits::NumCast + num_traits::NumRef
{
    fn try_cast<T: num_traits::NumCast>(self) -> Result<T, CastFailure<T, Self>> {
        try_cast(self)
    }

    fn cast<T: num_traits::NumCast>(self) -> T {
        cast(self)
    }

    fn to_i8(self) -> i8 {
        self.cast()
    }

    fn to_i16(self) -> i16 {
        self.cast()
    }

    fn to_i32(self) -> i32 {
        self.cast()
    }

    fn to_i64(self) -> i64 {
        self.cast()
    }

    fn to_i128(self) -> i128 {
        self.cast()
    }

    fn to_isize(self) -> isize {
        self.cast()
    }

    fn to_u8(self) -> u8 {
        self.cast()
    }

    fn to_u16(self) -> u16 {
        self.cast()
    }

    fn to_u32(self) -> u32 {
        self.cast()
    }

    fn to_u64(self) -> u64 {
        self.cast()
    }

    fn to_u128(self) -> u128 {
        self.cast()
    }

    fn to_usize(self) -> usize {
        self.cast()
    }

    fn to_f32(self) -> f32 {
        self.cast()
    }

    fn to_f64(self) -> f64 {
        self.cast()
    }

    fn two() -> Self {
        cast(2)
    }

    fn three() -> Self {
        cast(3)
    }

    fn four() -> Self {
        cast(4)
    }

    fn five() -> Self {
        cast(5)
    }

    fn six() -> Self {
        cast(6)
    }

    fn seven() -> Self {
        cast(7)
    }

    fn halved(self) -> Self {
        self / Self::two()
    }
}

impl<T> Num for T where
    T: Copy + Debug + Max + Min + num_traits::Num + num_traits::NumCast + num_traits::NumRef
{
}

pub trait Float: num_traits::Float + num_traits::FloatConst + Num {}
impl<T> Float for T where T: num_traits::Float + num_traits::FloatConst + Num {}