proportion/src/bounds.rs

31 lines
624 B
Rust

use crate::Internal;
use crate::Proportion;
pub trait Bounded {
const MIN: Self;
const MAX: Self;
}
macro_rules! impl_bounded {
($type:ty) => {
impl Bounded for $type {
const MIN: Self = <$type>::MIN;
const MAX: Self = <$type>::MAX;
}
};
}
impl_bounded!(u8);
impl_bounded!(u16);
impl_bounded!(u32);
impl_bounded!(u64);
impl_bounded!(u128);
impl<T: Internal> Proportion<T> {
pub const MIN: Self = Proportion { value: T::MIN };
pub const MAX: Self = Proportion { value: T::MAX };
pub const ZERO: Self = Self::MIN;
pub const ONE: Self = Self::MAX;
}