typerat/marker/notone.rs
1use crate::{Denominator, NonZeroUnsigned, Numerator, Q};
2use typenum::{Bit, NInt, PInt, UInt, Z0};
3
4pub trait Sealed {}
5
6impl Sealed for Z0 {}
7
8impl<U, B> Sealed for PInt<UInt<U, B>>
9where
10 U: NonZeroUnsigned,
11 B: Bit,
12{
13}
14
15impl<U> Sealed for NInt<U> where U: NonZeroUnsigned {}
16
17impl<N> Sealed for Q<N> where N: Numerator + NotOne {}
18
19impl<N, D> Sealed for Q<N, D>
20where
21 N: Numerator<D>,
22 D: Denominator + NotOne,
23{
24}
25
26/// Marker trait for not-one numbers.
27///
28/// # Examples
29///
30/// ```
31/// use typerat::*;
32///
33/// fn is_notone<T: NotOne>() -> bool {
34/// true
35/// }
36///
37/// assert!(is_notone::<Z0>());
38/// assert!(is_notone::<N1>());
39/// assert!(is_notone::<Q<Z0>>());
40/// assert!(is_notone::<Q<N1>>());
41/// assert!(is_notone::<Q<P2, P3>>());
42/// assert!(is_notone::<Q<N2, P3>>());
43/// ```
44///
45/// ```compile_fail
46/// # use typerat::*;
47/// #
48/// # fn is_notone<T: NotOne>() -> bool {
49/// # true
50/// # }
51/// #
52/// assert!(is_notone::<P1>());
53/// ```
54///
55/// ```compile_fail
56/// # use typerat::*;
57/// #
58/// # fn is_notone<T: NotOne>() -> bool {
59/// # true
60/// # }
61/// #
62/// assert!(is_notone::<Q<P1>>());
63/// ```
64pub trait NotOne: Sealed {}
65
66impl NotOne for Z0 {}
67
68impl<U, B> NotOne for PInt<UInt<U, B>>
69where
70 U: NonZeroUnsigned,
71 B: Bit,
72{
73}
74
75impl<U> NotOne for NInt<U> where U: NonZeroUnsigned {}
76
77impl<N> NotOne for Q<N> where N: Numerator + NotOne {}
78
79impl<N, D> NotOne for Q<N, D>
80where
81 N: Numerator<D>,
82 D: Denominator + NotOne,
83{
84}