inter_val/
bound.rs

1use crate::traits::{Flip, IntoGeneral};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
4pub struct Bound<T, B> {
5    pub limit: T,
6    pub bound_type: B,
7}
8
9impl<T, B: IntoGeneral> IntoGeneral for Bound<T, B> {
10    type General = Bound<T, B::General>;
11    fn into_general(self) -> Self::General {
12        Bound {
13            limit: self.limit,
14            bound_type: self.bound_type.into_general(),
15        }
16    }
17}
18
19impl<T, B: Flip> Flip for Bound<T, B> {
20    type Flip = Bound<T, B::Flip>;
21    fn flip(self) -> Self::Flip {
22        Bound {
23            limit: self.limit,
24            bound_type: self.bound_type.flip(),
25        }
26    }
27}
28
29impl<T, B> Bound<T, B> {
30    pub fn cast<U: From<T>>(self) -> Bound<U, B> {
31        Bound {
32            limit: self.limit.into(),
33            bound_type: self.bound_type,
34        }
35    }
36}
37impl<T: num::NumCast, B> Bound<T, B> {
38    pub fn try_cast<U: num::NumCast>(self) -> Option<Bound<U, B>> {
39        Some(Bound {
40            limit: num::cast(self.limit)?,
41            bound_type: self.bound_type,
42        })
43    }
44}