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
use crate::{traits::IntoGeneral, Bound, BoundType, Exclusive, Inclusive, Interval};

impl<T> From<T> for Bound<T, Inclusive> {
    fn from(t: T) -> Self {
        Self {
            limit: t,
            bound_type: Inclusive,
        }
    }
}
impl<T> From<T> for Bound<T, Exclusive> {
    fn from(t: T) -> Self {
        Self {
            limit: t,
            bound_type: Exclusive,
        }
    }
}

/// ```
/// use inter_val::{BoundType, Inclusive, Interval};
/// let src: Interval<i32, Inclusive> = Inclusive.at(0).to(Inclusive.at(10));
/// let dst: Interval<i32, BoundType> = src.into();
/// assert_eq!(dst.left().bound_type, BoundType::Inclusive);
/// assert_eq!(dst.right().bound_type, BoundType::Inclusive);
/// ```
impl<T> From<Interval<T, Inclusive>> for Interval<T, BoundType> {
    fn from(i: Interval<T, Inclusive>) -> Self {
        i.into_general()
    }
}

/// ```
/// use inter_val::{BoundType, Exclusive, Interval};
/// let src: Interval<i32, Exclusive> = Exclusive.at(0).to(Exclusive.at(10));
/// let dst: Interval<i32, BoundType> = src.into();
/// assert_eq!(dst.left().bound_type, BoundType::Exclusive);
/// assert_eq!(dst.right().bound_type, BoundType::Exclusive);
/// ```
impl<T> From<Interval<T, Exclusive>> for Interval<T, BoundType> {
    fn from(i: Interval<T, Exclusive>) -> Self {
        i.into_general()
    }
}

/// ```
/// use inter_val::{BoundType, Inclusive, Exclusive, Interval};
/// let src: Interval<i32, Inclusive, Exclusive> = Inclusive.at(0).to(Exclusive.at(10));
/// let dst: Interval<i32, BoundType> = src.into();
/// assert_eq!(dst.left().bound_type, BoundType::Inclusive);
/// assert_eq!(dst.right().bound_type, BoundType::Exclusive);
/// ```
impl<T> From<Interval<T, Inclusive, Exclusive>> for Interval<T, BoundType> {
    fn from(i: Interval<T, Inclusive, Exclusive>) -> Self {
        i.into_general()
    }
}

/// ```
/// use inter_val::{BoundType, Inclusive, Exclusive, Interval};
/// let src: Interval<i32, Exclusive, Inclusive> = Exclusive.at(0).to(Inclusive.at(10));
/// let dst: Interval<i32, BoundType> = src.into();
/// assert_eq!(dst.left().bound_type, BoundType::Exclusive);
/// assert_eq!(dst.right().bound_type, BoundType::Inclusive);
/// ```
impl<T> From<Interval<T, Exclusive, Inclusive>> for Interval<T, BoundType> {
    fn from(i: Interval<T, Exclusive, Inclusive>) -> Self {
        i.into_general()
    }
}

/// ```
/// use std::any::{Any, TypeId};
/// use inter_val::{Inclusive, Interval};
/// let a: Interval<_, _, _> = 3.into();
/// assert_eq!(a.type_id(), TypeId::of::<Interval<i32, Inclusive, Inclusive>>());
/// assert_eq!(a.left().limit, 3);
/// assert_eq!(a.right().limit, 3);
impl<T: PartialOrd + Clone> From<T> for Interval<T, Inclusive> {
    fn from(t: T) -> Self {
        Self::new(t.clone().into(), t.into())
    }
}