]>
Commit | Line | Data |
---|---|---|
60c5eb7d XL |
1 | use super::{From, TryFrom}; |
2 | use crate::num::TryFromIntError; | |
3 | ||
4 | mod private { | |
5 | /// This trait being unreachable from outside the crate | |
6 | /// prevents other implementations of the `FloatToInt` trait, | |
7 | /// which allows potentially adding more trait methods after the trait is `#[stable]`. | |
8 | #[unstable(feature = "convert_float_to_int", issue = "67057")] | |
9 | pub trait Sealed {} | |
10 | } | |
11 | ||
12 | /// Supporting trait for inherent methods of `f32` and `f64` such as `round_unchecked_to`. | |
13 | /// Typically doesn’t need to be used directly. | |
14 | #[unstable(feature = "convert_float_to_int", issue = "67057")] | |
15 | pub trait FloatToInt<Int>: private::Sealed + Sized { | |
ba9703b0 | 16 | #[unstable(feature = "convert_float_to_int", issue = "67057")] |
60c5eb7d | 17 | #[doc(hidden)] |
ba9703b0 | 18 | unsafe fn to_int_unchecked(self) -> Int; |
60c5eb7d XL |
19 | } |
20 | ||
21 | macro_rules! impl_float_to_int { | |
22 | ( $Float: ident => $( $Int: ident )+ ) => { | |
23 | #[unstable(feature = "convert_float_to_int", issue = "67057")] | |
24 | impl private::Sealed for $Float {} | |
25 | $( | |
26 | #[unstable(feature = "convert_float_to_int", issue = "67057")] | |
27 | impl FloatToInt<$Int> for $Float { | |
60c5eb7d XL |
28 | #[doc(hidden)] |
29 | #[inline] | |
ba9703b0 XL |
30 | unsafe fn to_int_unchecked(self) -> $Int { |
31 | #[cfg(bootstrap)] | |
32 | { | |
33 | crate::intrinsics::float_to_int_approx_unchecked(self) | |
34 | } | |
35 | #[cfg(not(bootstrap))] | |
36 | { | |
37 | crate::intrinsics::float_to_int_unchecked(self) | |
38 | } | |
60c5eb7d XL |
39 | } |
40 | } | |
41 | )+ | |
42 | } | |
43 | } | |
44 | ||
45 | impl_float_to_int!(f32 => u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize); | |
46 | impl_float_to_int!(f64 => u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize); | |
47 | ||
48 | // Conversion traits for primitive integer and float types | |
49 | // Conversions T -> T are covered by a blanket impl and therefore excluded | |
50 | // Some conversions from and to usize/isize are not implemented due to portability concerns | |
51 | macro_rules! impl_from { | |
52 | ($Small: ty, $Large: ty, #[$attr:meta], $doc: expr) => { | |
53 | #[$attr] | |
54 | #[doc = $doc] | |
55 | impl From<$Small> for $Large { | |
56 | #[inline] | |
dfeec247 XL |
57 | fn from(small: $Small) -> Self { |
58 | small as Self | |
60c5eb7d XL |
59 | } |
60 | } | |
61 | }; | |
62 | ($Small: ty, $Large: ty, #[$attr:meta]) => { | |
63 | impl_from!($Small, | |
64 | $Large, | |
65 | #[$attr], | |
66 | concat!("Converts `", | |
67 | stringify!($Small), | |
68 | "` to `", | |
69 | stringify!($Large), | |
70 | "` losslessly.")); | |
71 | } | |
72 | } | |
73 | ||
74 | macro_rules! impl_from_bool { | |
75 | ($target: ty, #[$attr:meta]) => { | |
76 | impl_from!(bool, $target, #[$attr], concat!("Converts a `bool` to a `", | |
77 | stringify!($target), "`. The resulting value is `0` for `false` and `1` for `true` | |
78 | values. | |
79 | ||
80 | # Examples | |
81 | ||
82 | ``` | |
83 | assert_eq!(", stringify!($target), "::from(true), 1); | |
84 | assert_eq!(", stringify!($target), "::from(false), 0); | |
85 | ```")); | |
86 | }; | |
87 | } | |
88 | ||
89 | // Bool -> Any | |
90 | impl_from_bool! { u8, #[stable(feature = "from_bool", since = "1.28.0")] } | |
91 | impl_from_bool! { u16, #[stable(feature = "from_bool", since = "1.28.0")] } | |
92 | impl_from_bool! { u32, #[stable(feature = "from_bool", since = "1.28.0")] } | |
93 | impl_from_bool! { u64, #[stable(feature = "from_bool", since = "1.28.0")] } | |
94 | impl_from_bool! { u128, #[stable(feature = "from_bool", since = "1.28.0")] } | |
95 | impl_from_bool! { usize, #[stable(feature = "from_bool", since = "1.28.0")] } | |
96 | impl_from_bool! { i8, #[stable(feature = "from_bool", since = "1.28.0")] } | |
97 | impl_from_bool! { i16, #[stable(feature = "from_bool", since = "1.28.0")] } | |
98 | impl_from_bool! { i32, #[stable(feature = "from_bool", since = "1.28.0")] } | |
99 | impl_from_bool! { i64, #[stable(feature = "from_bool", since = "1.28.0")] } | |
100 | impl_from_bool! { i128, #[stable(feature = "from_bool", since = "1.28.0")] } | |
101 | impl_from_bool! { isize, #[stable(feature = "from_bool", since = "1.28.0")] } | |
102 | ||
103 | // Unsigned -> Unsigned | |
104 | impl_from! { u8, u16, #[stable(feature = "lossless_int_conv", since = "1.5.0")] } | |
105 | impl_from! { u8, u32, #[stable(feature = "lossless_int_conv", since = "1.5.0")] } | |
106 | impl_from! { u8, u64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] } | |
107 | impl_from! { u8, u128, #[stable(feature = "i128", since = "1.26.0")] } | |
108 | impl_from! { u8, usize, #[stable(feature = "lossless_int_conv", since = "1.5.0")] } | |
109 | impl_from! { u16, u32, #[stable(feature = "lossless_int_conv", since = "1.5.0")] } | |
110 | impl_from! { u16, u64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] } | |
111 | impl_from! { u16, u128, #[stable(feature = "i128", since = "1.26.0")] } | |
112 | impl_from! { u32, u64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] } | |
113 | impl_from! { u32, u128, #[stable(feature = "i128", since = "1.26.0")] } | |
114 | impl_from! { u64, u128, #[stable(feature = "i128", since = "1.26.0")] } | |
115 | ||
116 | // Signed -> Signed | |
117 | impl_from! { i8, i16, #[stable(feature = "lossless_int_conv", since = "1.5.0")] } | |
118 | impl_from! { i8, i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")] } | |
119 | impl_from! { i8, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] } | |
120 | impl_from! { i8, i128, #[stable(feature = "i128", since = "1.26.0")] } | |
121 | impl_from! { i8, isize, #[stable(feature = "lossless_int_conv", since = "1.5.0")] } | |
122 | impl_from! { i16, i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")] } | |
123 | impl_from! { i16, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] } | |
124 | impl_from! { i16, i128, #[stable(feature = "i128", since = "1.26.0")] } | |
125 | impl_from! { i32, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] } | |
126 | impl_from! { i32, i128, #[stable(feature = "i128", since = "1.26.0")] } | |
127 | impl_from! { i64, i128, #[stable(feature = "i128", since = "1.26.0")] } | |
128 | ||
129 | // Unsigned -> Signed | |
130 | impl_from! { u8, i16, #[stable(feature = "lossless_int_conv", since = "1.5.0")] } | |
131 | impl_from! { u8, i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")] } | |
132 | impl_from! { u8, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] } | |
133 | impl_from! { u8, i128, #[stable(feature = "i128", since = "1.26.0")] } | |
134 | impl_from! { u16, i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")] } | |
135 | impl_from! { u16, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] } | |
136 | impl_from! { u16, i128, #[stable(feature = "i128", since = "1.26.0")] } | |
137 | impl_from! { u32, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] } | |
138 | impl_from! { u32, i128, #[stable(feature = "i128", since = "1.26.0")] } | |
139 | impl_from! { u64, i128, #[stable(feature = "i128", since = "1.26.0")] } | |
140 | ||
141 | // The C99 standard defines bounds on INTPTR_MIN, INTPTR_MAX, and UINTPTR_MAX | |
142 | // which imply that pointer-sized integers must be at least 16 bits: | |
143 | // https://port70.net/~nsz/c/c99/n1256.html#7.18.2.4 | |
144 | impl_from! { u16, usize, #[stable(feature = "lossless_iusize_conv", since = "1.26.0")] } | |
145 | impl_from! { u8, isize, #[stable(feature = "lossless_iusize_conv", since = "1.26.0")] } | |
146 | impl_from! { i16, isize, #[stable(feature = "lossless_iusize_conv", since = "1.26.0")] } | |
147 | ||
148 | // RISC-V defines the possibility of a 128-bit address space (RV128). | |
149 | ||
150 | // CHERI proposes 256-bit “capabilities”. Unclear if this would be relevant to usize/isize. | |
151 | // https://www.cl.cam.ac.uk/research/security/ctsrd/pdfs/20171017a-cheri-poster.pdf | |
152 | // http://www.csl.sri.com/users/neumann/2012resolve-cheri.pdf | |
153 | ||
154 | // Note: integers can only be represented with full precision in a float if | |
155 | // they fit in the significand, which is 24 bits in f32 and 53 bits in f64. | |
156 | // Lossy float conversions are not implemented at this time. | |
157 | ||
158 | // Signed -> Float | |
159 | impl_from! { i8, f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")] } | |
160 | impl_from! { i8, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")] } | |
161 | impl_from! { i16, f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")] } | |
162 | impl_from! { i16, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")] } | |
163 | impl_from! { i32, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")] } | |
164 | ||
165 | // Unsigned -> Float | |
166 | impl_from! { u8, f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")] } | |
167 | impl_from! { u8, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")] } | |
168 | impl_from! { u16, f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")] } | |
169 | impl_from! { u16, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")] } | |
170 | impl_from! { u32, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")] } | |
171 | ||
172 | // Float -> Float | |
173 | impl_from! { f32, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")] } | |
174 | ||
175 | // no possible bounds violation | |
176 | macro_rules! try_from_unbounded { | |
177 | ($source:ty, $($target:ty),*) => {$( | |
178 | #[stable(feature = "try_from", since = "1.34.0")] | |
179 | impl TryFrom<$source> for $target { | |
180 | type Error = TryFromIntError; | |
181 | ||
182 | /// Try to create the target number type from a source | |
183 | /// number type. This returns an error if the source value | |
184 | /// is outside of the range of the target type. | |
185 | #[inline] | |
186 | fn try_from(value: $source) -> Result<Self, Self::Error> { | |
dfeec247 | 187 | Ok(value as Self) |
60c5eb7d XL |
188 | } |
189 | } | |
190 | )*} | |
191 | } | |
192 | ||
193 | // only negative bounds | |
194 | macro_rules! try_from_lower_bounded { | |
195 | ($source:ty, $($target:ty),*) => {$( | |
196 | #[stable(feature = "try_from", since = "1.34.0")] | |
197 | impl TryFrom<$source> for $target { | |
198 | type Error = TryFromIntError; | |
199 | ||
200 | /// Try to create the target number type from a source | |
201 | /// number type. This returns an error if the source value | |
202 | /// is outside of the range of the target type. | |
203 | #[inline] | |
dfeec247 | 204 | fn try_from(u: $source) -> Result<Self, Self::Error> { |
60c5eb7d | 205 | if u >= 0 { |
dfeec247 | 206 | Ok(u as Self) |
60c5eb7d XL |
207 | } else { |
208 | Err(TryFromIntError(())) | |
209 | } | |
210 | } | |
211 | } | |
212 | )*} | |
213 | } | |
214 | ||
215 | // unsigned to signed (only positive bound) | |
216 | macro_rules! try_from_upper_bounded { | |
217 | ($source:ty, $($target:ty),*) => {$( | |
218 | #[stable(feature = "try_from", since = "1.34.0")] | |
219 | impl TryFrom<$source> for $target { | |
220 | type Error = TryFromIntError; | |
221 | ||
222 | /// Try to create the target number type from a source | |
223 | /// number type. This returns an error if the source value | |
224 | /// is outside of the range of the target type. | |
225 | #[inline] | |
dfeec247 XL |
226 | fn try_from(u: $source) -> Result<Self, Self::Error> { |
227 | if u > (Self::max_value() as $source) { | |
60c5eb7d XL |
228 | Err(TryFromIntError(())) |
229 | } else { | |
dfeec247 | 230 | Ok(u as Self) |
60c5eb7d XL |
231 | } |
232 | } | |
233 | } | |
234 | )*} | |
235 | } | |
236 | ||
237 | // all other cases | |
238 | macro_rules! try_from_both_bounded { | |
239 | ($source:ty, $($target:ty),*) => {$( | |
240 | #[stable(feature = "try_from", since = "1.34.0")] | |
241 | impl TryFrom<$source> for $target { | |
242 | type Error = TryFromIntError; | |
243 | ||
244 | /// Try to create the target number type from a source | |
245 | /// number type. This returns an error if the source value | |
246 | /// is outside of the range of the target type. | |
247 | #[inline] | |
dfeec247 XL |
248 | fn try_from(u: $source) -> Result<Self, Self::Error> { |
249 | let min = Self::min_value() as $source; | |
250 | let max = Self::max_value() as $source; | |
60c5eb7d XL |
251 | if u < min || u > max { |
252 | Err(TryFromIntError(())) | |
253 | } else { | |
dfeec247 | 254 | Ok(u as Self) |
60c5eb7d XL |
255 | } |
256 | } | |
257 | } | |
258 | )*} | |
259 | } | |
260 | ||
261 | macro_rules! rev { | |
262 | ($mac:ident, $source:ty, $($target:ty),*) => {$( | |
263 | $mac!($target, $source); | |
264 | )*} | |
265 | } | |
266 | ||
267 | // intra-sign conversions | |
268 | try_from_upper_bounded!(u16, u8); | |
269 | try_from_upper_bounded!(u32, u16, u8); | |
270 | try_from_upper_bounded!(u64, u32, u16, u8); | |
271 | try_from_upper_bounded!(u128, u64, u32, u16, u8); | |
272 | ||
273 | try_from_both_bounded!(i16, i8); | |
274 | try_from_both_bounded!(i32, i16, i8); | |
275 | try_from_both_bounded!(i64, i32, i16, i8); | |
276 | try_from_both_bounded!(i128, i64, i32, i16, i8); | |
277 | ||
278 | // unsigned-to-signed | |
279 | try_from_upper_bounded!(u8, i8); | |
280 | try_from_upper_bounded!(u16, i8, i16); | |
281 | try_from_upper_bounded!(u32, i8, i16, i32); | |
282 | try_from_upper_bounded!(u64, i8, i16, i32, i64); | |
283 | try_from_upper_bounded!(u128, i8, i16, i32, i64, i128); | |
284 | ||
285 | // signed-to-unsigned | |
286 | try_from_lower_bounded!(i8, u8, u16, u32, u64, u128); | |
287 | try_from_lower_bounded!(i16, u16, u32, u64, u128); | |
288 | try_from_lower_bounded!(i32, u32, u64, u128); | |
289 | try_from_lower_bounded!(i64, u64, u128); | |
290 | try_from_lower_bounded!(i128, u128); | |
291 | try_from_both_bounded!(i16, u8); | |
292 | try_from_both_bounded!(i32, u16, u8); | |
293 | try_from_both_bounded!(i64, u32, u16, u8); | |
294 | try_from_both_bounded!(i128, u64, u32, u16, u8); | |
295 | ||
296 | // usize/isize | |
297 | try_from_upper_bounded!(usize, isize); | |
298 | try_from_lower_bounded!(isize, usize); | |
299 | ||
300 | #[cfg(target_pointer_width = "16")] | |
301 | mod ptr_try_from_impls { | |
302 | use super::TryFromIntError; | |
303 | use crate::convert::TryFrom; | |
304 | ||
305 | try_from_upper_bounded!(usize, u8); | |
306 | try_from_unbounded!(usize, u16, u32, u64, u128); | |
307 | try_from_upper_bounded!(usize, i8, i16); | |
308 | try_from_unbounded!(usize, i32, i64, i128); | |
309 | ||
310 | try_from_both_bounded!(isize, u8); | |
311 | try_from_lower_bounded!(isize, u16, u32, u64, u128); | |
312 | try_from_both_bounded!(isize, i8); | |
313 | try_from_unbounded!(isize, i16, i32, i64, i128); | |
314 | ||
315 | rev!(try_from_upper_bounded, usize, u32, u64, u128); | |
316 | rev!(try_from_lower_bounded, usize, i8, i16); | |
317 | rev!(try_from_both_bounded, usize, i32, i64, i128); | |
318 | ||
319 | rev!(try_from_upper_bounded, isize, u16, u32, u64, u128); | |
320 | rev!(try_from_both_bounded, isize, i32, i64, i128); | |
321 | } | |
322 | ||
323 | #[cfg(target_pointer_width = "32")] | |
324 | mod ptr_try_from_impls { | |
325 | use super::TryFromIntError; | |
326 | use crate::convert::TryFrom; | |
327 | ||
328 | try_from_upper_bounded!(usize, u8, u16); | |
329 | try_from_unbounded!(usize, u32, u64, u128); | |
330 | try_from_upper_bounded!(usize, i8, i16, i32); | |
331 | try_from_unbounded!(usize, i64, i128); | |
332 | ||
333 | try_from_both_bounded!(isize, u8, u16); | |
334 | try_from_lower_bounded!(isize, u32, u64, u128); | |
335 | try_from_both_bounded!(isize, i8, i16); | |
336 | try_from_unbounded!(isize, i32, i64, i128); | |
337 | ||
338 | rev!(try_from_unbounded, usize, u32); | |
339 | rev!(try_from_upper_bounded, usize, u64, u128); | |
340 | rev!(try_from_lower_bounded, usize, i8, i16, i32); | |
341 | rev!(try_from_both_bounded, usize, i64, i128); | |
342 | ||
343 | rev!(try_from_unbounded, isize, u16); | |
344 | rev!(try_from_upper_bounded, isize, u32, u64, u128); | |
345 | rev!(try_from_unbounded, isize, i32); | |
346 | rev!(try_from_both_bounded, isize, i64, i128); | |
347 | } | |
348 | ||
349 | #[cfg(target_pointer_width = "64")] | |
350 | mod ptr_try_from_impls { | |
351 | use super::TryFromIntError; | |
352 | use crate::convert::TryFrom; | |
353 | ||
354 | try_from_upper_bounded!(usize, u8, u16, u32); | |
355 | try_from_unbounded!(usize, u64, u128); | |
356 | try_from_upper_bounded!(usize, i8, i16, i32, i64); | |
357 | try_from_unbounded!(usize, i128); | |
358 | ||
359 | try_from_both_bounded!(isize, u8, u16, u32); | |
360 | try_from_lower_bounded!(isize, u64, u128); | |
361 | try_from_both_bounded!(isize, i8, i16, i32); | |
362 | try_from_unbounded!(isize, i64, i128); | |
363 | ||
364 | rev!(try_from_unbounded, usize, u32, u64); | |
365 | rev!(try_from_upper_bounded, usize, u128); | |
366 | rev!(try_from_lower_bounded, usize, i8, i16, i32, i64); | |
367 | rev!(try_from_both_bounded, usize, i128); | |
368 | ||
369 | rev!(try_from_unbounded, isize, u16, u32); | |
370 | rev!(try_from_upper_bounded, isize, u64, u128); | |
371 | rev!(try_from_unbounded, isize, i32, i64); | |
372 | rev!(try_from_both_bounded, isize, i128); | |
373 | } | |
374 | ||
375 | // Conversion traits for non-zero integer types | |
376 | use crate::num::NonZeroI128; | |
377 | use crate::num::NonZeroI16; | |
378 | use crate::num::NonZeroI32; | |
379 | use crate::num::NonZeroI64; | |
380 | use crate::num::NonZeroI8; | |
381 | use crate::num::NonZeroIsize; | |
382 | use crate::num::NonZeroU128; | |
383 | use crate::num::NonZeroU16; | |
384 | use crate::num::NonZeroU32; | |
385 | use crate::num::NonZeroU64; | |
386 | use crate::num::NonZeroU8; | |
387 | use crate::num::NonZeroUsize; | |
388 | ||
389 | macro_rules! nzint_impl_from { | |
390 | ($Small: ty, $Large: ty, #[$attr:meta], $doc: expr) => { | |
391 | #[$attr] | |
392 | #[doc = $doc] | |
393 | impl From<$Small> for $Large { | |
394 | #[inline] | |
dfeec247 | 395 | fn from(small: $Small) -> Self { |
60c5eb7d XL |
396 | // SAFETY: input type guarantees the value is non-zero |
397 | unsafe { | |
dfeec247 | 398 | Self::new_unchecked(small.get().into()) |
60c5eb7d XL |
399 | } |
400 | } | |
401 | } | |
402 | }; | |
403 | ($Small: ty, $Large: ty, #[$attr:meta]) => { | |
404 | nzint_impl_from!($Small, | |
405 | $Large, | |
406 | #[$attr], | |
407 | concat!("Converts `", | |
408 | stringify!($Small), | |
409 | "` to `", | |
410 | stringify!($Large), | |
411 | "` losslessly.")); | |
412 | } | |
413 | } | |
414 | ||
415 | // Non-zero Unsigned -> Non-zero Unsigned | |
416 | nzint_impl_from! { NonZeroU8, NonZeroU16, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
417 | nzint_impl_from! { NonZeroU8, NonZeroU32, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
418 | nzint_impl_from! { NonZeroU8, NonZeroU64, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
419 | nzint_impl_from! { NonZeroU8, NonZeroU128, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
420 | nzint_impl_from! { NonZeroU8, NonZeroUsize, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
421 | nzint_impl_from! { NonZeroU16, NonZeroU32, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
422 | nzint_impl_from! { NonZeroU16, NonZeroU64, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
423 | nzint_impl_from! { NonZeroU16, NonZeroU128, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
424 | nzint_impl_from! { NonZeroU16, NonZeroUsize, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
425 | nzint_impl_from! { NonZeroU32, NonZeroU64, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
426 | nzint_impl_from! { NonZeroU32, NonZeroU128, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
427 | nzint_impl_from! { NonZeroU64, NonZeroU128, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
428 | ||
429 | // Non-zero Signed -> Non-zero Signed | |
430 | nzint_impl_from! { NonZeroI8, NonZeroI16, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
431 | nzint_impl_from! { NonZeroI8, NonZeroI32, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
432 | nzint_impl_from! { NonZeroI8, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
433 | nzint_impl_from! { NonZeroI8, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
434 | nzint_impl_from! { NonZeroI8, NonZeroIsize, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
435 | nzint_impl_from! { NonZeroI16, NonZeroI32, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
436 | nzint_impl_from! { NonZeroI16, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
437 | nzint_impl_from! { NonZeroI16, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
438 | nzint_impl_from! { NonZeroI16, NonZeroIsize, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
439 | nzint_impl_from! { NonZeroI32, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
440 | nzint_impl_from! { NonZeroI32, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
441 | nzint_impl_from! { NonZeroI64, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
442 | ||
443 | // NonZero UnSigned -> Non-zero Signed | |
444 | nzint_impl_from! { NonZeroU8, NonZeroI16, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
445 | nzint_impl_from! { NonZeroU8, NonZeroI32, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
446 | nzint_impl_from! { NonZeroU8, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
447 | nzint_impl_from! { NonZeroU8, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
448 | nzint_impl_from! { NonZeroU8, NonZeroIsize, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
449 | nzint_impl_from! { NonZeroU16, NonZeroI32, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
450 | nzint_impl_from! { NonZeroU16, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
451 | nzint_impl_from! { NonZeroU16, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
452 | nzint_impl_from! { NonZeroU32, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
453 | nzint_impl_from! { NonZeroU32, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] } | |
454 | nzint_impl_from! { NonZeroU64, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] } |