]>
git.proxmox.com Git - cargo.git/blob - vendor/typenum/src/marker_traits.rs
1 //! All of the **marker traits** used in typenum.
3 //! Note that the definition here for marker traits is slightly different than
4 //! the conventional one -- we include traits with functions that convert a type
5 //! to the corresponding value, as well as associated constants that do the
8 //! For example, the `Integer` trait includes the function (among others) `fn
9 //! to_i32() -> i32` and the associated constant `I32` so that one can do this:
12 //! use typenum::{N42, Integer};
14 //! assert_eq!(-42, N42::to_i32());
15 //! assert_eq!(-42, N42::I32);
19 /// A **marker trait** to designate that a type is not zero. All number types in this
20 /// crate implement `NonZero` except `B0`, `U0`, and `Z0`.
23 /// A **Marker trait** for the types `Greater`, `Equal`, and `Less`.
25 /// This trait should not be implemented for anything outside this crate.
27 #[allow(missing_docs)]
28 fn to_ordering() -> ::core
::cmp
::Ordering
;
31 /// The **marker trait** for compile time bits.
33 /// This trait should not be implemented for anything outside this crate.
35 #[allow(missing_docs)]
37 #[allow(missing_docs)]
40 #[allow(missing_docs)]
42 #[allow(missing_docs)]
46 /// The **marker trait** for compile time unsigned integers.
48 /// This trait should not be implemented for anything outside this crate.
52 /// use typenum::{U3, Unsigned};
54 /// assert_eq!(U3::to_u32(), 3);
55 /// assert_eq!(U3::I32, 3);
58 #[allow(missing_docs)]
60 #[allow(missing_docs)]
62 #[allow(missing_docs)]
64 #[allow(missing_docs)]
66 #[cfg(feature = "i128")]
67 #[allow(missing_docs)]
69 #[allow(missing_docs)]
72 #[allow(missing_docs)]
74 #[allow(missing_docs)]
76 #[allow(missing_docs)]
78 #[allow(missing_docs)]
80 #[cfg(feature = "i128")]
81 #[allow(missing_docs)]
83 #[allow(missing_docs)]
86 #[allow(missing_docs)]
88 #[allow(missing_docs)]
90 #[allow(missing_docs)]
92 #[allow(missing_docs)]
94 #[cfg(feature = "i128")]
95 #[allow(missing_docs)]
97 #[allow(missing_docs)]
98 fn to_usize() -> usize;
100 #[allow(missing_docs)]
102 #[allow(missing_docs)]
104 #[allow(missing_docs)]
106 #[allow(missing_docs)]
108 #[cfg(feature = "i128")]
109 #[allow(missing_docs)]
110 fn to_i128() -> i128
;
111 #[allow(missing_docs)]
112 fn to_isize() -> isize;
115 /// The **marker trait** for compile time signed integers.
117 /// This trait should not be implemented for anything outside this crate.
121 /// use typenum::{P3, Integer};
123 /// assert_eq!(P3::to_i32(), 3);
124 /// assert_eq!(P3::I32, 3);
127 #[allow(missing_docs)]
129 #[allow(missing_docs)]
131 #[allow(missing_docs)]
133 #[allow(missing_docs)]
135 #[cfg(feature = "i128")]
136 #[allow(missing_docs)]
138 #[allow(missing_docs)]
141 #[allow(missing_docs)]
143 #[allow(missing_docs)]
145 #[allow(missing_docs)]
147 #[allow(missing_docs)]
149 #[cfg(feature = "i128")]
150 #[allow(missing_docs)]
151 fn to_i128() -> i128
;
152 #[allow(missing_docs)]
153 fn to_isize() -> isize;
156 /// The **marker trait** for type-level arrays of type-level numbers.
158 /// This trait should not be implemented for anything outside this crate.
160 /// Someday, it may contain an associated constant to produce a runtime array,
161 /// like the other marker traits here. However, that is blocked by [this
162 /// issue](https://github.com/rust-lang/rust/issues/44168).
163 pub trait TypeArray {}
165 /// The **marker trait** for type-level numbers which are a power of two.
167 /// This trait should not be implemented for anything outside this crate.
171 /// Here's a working example:
174 /// use typenum::{P4, P8, PowerOfTwo};
176 /// fn only_p2<P: PowerOfTwo>() { }
182 /// Numbers which are not a power of two will fail to compile in this example:
184 /// ```rust,compile_fail
185 /// use typenum::{P9, P511, P1023, PowerOfTwo};
187 /// fn only_p2<P: PowerOfTwo>() { }
190 /// only_p2::<P511>();
191 /// only_p2::<P1023>();
194 pub trait PowerOfTwo {}