Skip to main content

yolol_number/traits/
mod.rs

1use std::fmt::{Display, Debug};
2use std::str::FromStr;
3use num_traits::*;
4
5mod yolol_ops;
6pub use yolol_ops::YololOps;
7
8/// Trait bounds for the various operations required for a compliant
9/// `YololOps` implementation. Requires `ArgBounds<Self>`, implying the type
10/// can be used as an argument for a `YololNumber` backed by itself.
11pub trait InnerBounds:
12    // These are just the bounds required to get YololOps implemented correctly
13    ArgBounds<Self> + Signed + Bounded + CheckedAdd + CheckedSub + CheckedMul + CheckedDiv + CheckedRem + One + Zero + PartialOrd
14
15    // These bounds are regular convenience ones that makes numbers behave nicer
16    + Eq + PartialEq + Ord + FromStr {}
17
18impl<T:
19    ArgBounds<Self> + Signed + Bounded + CheckedAdd + CheckedSub + CheckedMul + 
20    CheckedDiv + CheckedRem + One + Zero + PartialOrd +
21    Eq + PartialEq + Ord + FromStr>
22InnerBounds for T {}
23
24/// Trait bounds extending from `NumBounds` to allow the type to be
25/// an argument to a `YololNumber<T>`.
26pub trait ArgBounds<T: 'static + Copy + NumBounds>: NumBounds + AsPrimitive<T> {}
27
28impl<T, U> ArgBounds<T> for U
29where T: 'static + Copy + NumBounds,
30      U: NumBounds + AsPrimitive<T>
31{}
32
33/// Standard traits considered the base of any types interacting
34/// with a `YololNumber`. Generally isn't used itself, as it's transitively
35/// a bound for `ArgBounds` and `NumBounds`.
36pub trait NumBounds: Display + Debug + NumCast {}
37
38impl<T: Display + Debug + NumCast> NumBounds for T {}