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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#![doc = include_str!("../README.md")]
#![cfg_attr(feature = "marker_trait_attr", feature(marker_trait_attr))]
#![cfg_attr(feature = "never_type", feature(never_type))]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![no_std]

pub use {prim_signed_int::PrimSignedInt, prim_unsigned_int::PrimUnsignedInt};

/// [Marker trait](https://blog.rust-lang.org/2015/05/11/traits.html#:~:text=Markers.,both%20generics%20and%20trait%20objects.)
/// for [primitive integers](https://doc.rust-lang.org/reference/types/numeric.html#integer-types)
#[cfg_attr(feature = "marker_trait_attr", marker)]
pub trait PrimInt: PrimNum {}

#[cfg(not(feature = "marker_trait_attr"))]
mod prim_int_impl {
    impl super::PrimInt for u8 {}
    impl super::PrimInt for u16 {}
    impl super::PrimInt for u32 {}
    impl super::PrimInt for u64 {}
    impl super::PrimInt for u128 {}
    impl super::PrimInt for usize {}

    impl super::PrimInt for i8 {}
    impl super::PrimInt for i16 {}
    impl super::PrimInt for i32 {}
    impl super::PrimInt for i64 {}
    impl super::PrimInt for i128 {}
    impl super::PrimInt for isize {}
}

#[cfg(feature = "marker_trait_attr")]
mod prim_int_impl {
    impl<T: super::PrimUnsignedInt> super::PrimInt for T {}
    impl<T: super::PrimSignedInt> super::PrimInt for T {}
}

mod prim_unsigned_int {
    /// [Marker trait](https://blog.rust-lang.org/2015/05/11/traits.html#:~:text=Markers.,both%20generics%20and%20trait%20objects.)
    /// for [primitive unsigned integers](https://doc.rust-lang.org/reference/types/numeric.html#integer-types)
    #[cfg_attr(feature = "marker_trait_attr", marker)]
    pub trait PrimUnsignedInt: super::PrimInt {}

    impl PrimUnsignedInt for u8 {}
    impl PrimUnsignedInt for u16 {}
    impl PrimUnsignedInt for u32 {}
    impl PrimUnsignedInt for u64 {}
    impl PrimUnsignedInt for u128 {}
    impl PrimUnsignedInt for usize {}
}

mod prim_signed_int {
    /// [Marker trait](https://blog.rust-lang.org/2015/05/11/traits.html#:~:text=Markers.,both%20generics%20and%20trait%20objects.)
    /// for [primitive signed integers](https://doc.rust-lang.org/reference/types/numeric.html#integer-types)
    #[cfg_attr(feature = "marker_trait_attr", marker)]
    pub trait PrimSignedInt: super::PrimInt {}

    impl PrimSignedInt for i8 {}
    impl PrimSignedInt for i16 {}
    impl PrimSignedInt for i32 {}
    impl PrimSignedInt for i64 {}
    impl PrimSignedInt for i128 {}
    impl PrimSignedInt for isize {}
}

/// [Marker trait](https://blog.rust-lang.org/2015/05/11/traits.html#:~:text=Markers.,both%20generics%20and%20trait%20objects.)
/// for [primitive floating point types](https://doc.rust-lang.org/reference/types/numeric.html#floating-point-types)
#[cfg_attr(feature = "marker_trait_attr", marker)]
pub trait PrimFloat: PrimNum {}

#[cfg(feature = "marker_trait_attr")]
mod prim_num_impl {
    impl<T: crate::PrimFloat> crate::PrimNum for T {}
    impl<T: crate::PrimInt> crate::PrimNum for T {}
}

mod prim_float_impl {
    impl crate::PrimFloat for f32 {}
    impl crate::PrimFloat for f64 {}
}

/// [Marker trait](https://blog.rust-lang.org/2015/05/11/traits.html#:~:text=Markers.,both%20generics%20and%20trait%20objects.)
/// for [primitive numeric types](https://doc.rust-lang.org/reference/types/numeric.html).
#[cfg_attr(feature = "marker_trait_attr", marker)]
pub trait PrimNum: Prim {}

#[cfg(not(feature = "marker_trait_attr"))]
mod prim_num_impl {
    impl crate::PrimNum for u8 {}
    impl crate::PrimNum for u16 {}
    impl crate::PrimNum for u32 {}
    impl crate::PrimNum for u64 {}
    impl crate::PrimNum for u128 {}
    impl crate::PrimNum for usize {}

    impl crate::PrimNum for i8 {}
    impl crate::PrimNum for i16 {}
    impl crate::PrimNum for i32 {}
    impl crate::PrimNum for i64 {}
    impl crate::PrimNum for i128 {}
    impl crate::PrimNum for isize {}

    impl crate::PrimNum for f32 {}
    impl crate::PrimNum for f64 {}
}

/// [Marker trait](https://blog.rust-lang.org/2015/05/11/traits.html#:~:text=Markers.,both%20generics%20and%20trait%20objects.)
/// for [primitive textual types](https://doc.rust-lang.org/reference/types/textual.html)
#[cfg_attr(feature = "marker_trait_attr", marker)]
pub trait PrimTextual {}

impl PrimTextual for char {}
impl PrimTextual for str {}

/// [Marker trait](https://blog.rust-lang.org/2015/05/11/traits.html#:~:text=Markers.,both%20generics%20and%20trait%20objects.)
/// for [primitive types](https://doc.rust-lang.org/reference/types.html)
#[cfg_attr(feature = "marker_trait_attr", marker)]
pub trait Prim {}

#[cfg(not(feature = "marker_trait_attr"))]
mod prim_impl {
    impl crate::Prim for bool {}

    impl crate::Prim for u8 {}
    impl crate::Prim for u16 {}
    impl crate::Prim for u32 {}
    impl crate::Prim for u64 {}
    impl crate::Prim for u128 {}
    impl crate::Prim for usize {}

    impl crate::Prim for i8 {}
    impl crate::Prim for i16 {}
    impl crate::Prim for i32 {}
    impl crate::Prim for i64 {}
    impl crate::Prim for i128 {}
    impl crate::Prim for isize {}

    impl crate::Prim for f32 {}
    impl crate::Prim for f64 {}

    impl crate::Prim for char {}
    impl crate::Prim for str {}

    #[cfg_attr(docsrs, doc(cfg(feature = "never_type")))]
    #[cfg(feature = "never_type")]
    impl crate::Prim for ! {}
}

#[cfg(feature = "marker_trait_attr")]
mod prim_impl {
    impl crate::Prim for bool {}
    impl<T: crate::PrimNum> crate::Prim for T {}
    impl<T: crate::PrimTextual> crate::Prim for T {}

    #[cfg_attr(docsrs, doc(cfg(feature = "never_type")))]
    #[cfg(feature = "never_type")]
    impl crate::Prim for ! {}
}