1use crate::num::TryFromIntError;
2
3mod private {
4 #[unstable(feature = "convert_float_to_int", issue = "67057")]
8 pub trait Sealed {}
9}
10
11#[unstable(feature = "convert_float_to_int", issue = "67057")]
14pub trait FloatToInt<Int>: private::Sealed + Sized {
15 #[unstable(feature = "convert_float_to_int", issue = "67057")]
16 #[doc(hidden)]
17 unsafe fn to_int_unchecked(self) -> Int;
18}
19
20macro_rules! impl_float_to_int {
21 ($Float:ty => $($Int:ty),+) => {
22 #[unstable(feature = "convert_float_to_int", issue = "67057")]
23 impl private::Sealed for $Float {}
24 $(
25 #[unstable(feature = "convert_float_to_int", issue = "67057")]
26 impl FloatToInt<$Int> for $Float {
27 #[inline]
28 unsafe fn to_int_unchecked(self) -> $Int {
29 unsafe { crate::intrinsics::float_to_int_unchecked(self) }
31 }
32 }
33 )+
34 }
35}
36
37#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl private::Sealed for f16 { }
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u8> for f16 {
#[inline]
unsafe fn to_int_unchecked(self) -> u8 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u16> for f16 {
#[inline]
unsafe fn to_int_unchecked(self) -> u16 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u32> for f16 {
#[inline]
unsafe fn to_int_unchecked(self) -> u32 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u64> for f16 {
#[inline]
unsafe fn to_int_unchecked(self) -> u64 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u128> for f16 {
#[inline]
unsafe fn to_int_unchecked(self) -> u128 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<usize> for f16 {
#[inline]
unsafe fn to_int_unchecked(self) -> usize {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i8> for f16 {
#[inline]
unsafe fn to_int_unchecked(self) -> i8 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i16> for f16 {
#[inline]
unsafe fn to_int_unchecked(self) -> i16 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i32> for f16 {
#[inline]
unsafe fn to_int_unchecked(self) -> i32 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i64> for f16 {
#[inline]
unsafe fn to_int_unchecked(self) -> i64 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i128> for f16 {
#[inline]
unsafe fn to_int_unchecked(self) -> i128 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<isize> for f16 {
#[inline]
unsafe fn to_int_unchecked(self) -> isize {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}impl_float_to_int!(f16 => u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
38#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl private::Sealed for f32 { }
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u8> for f32 {
#[inline]
unsafe fn to_int_unchecked(self) -> u8 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u16> for f32 {
#[inline]
unsafe fn to_int_unchecked(self) -> u16 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u32> for f32 {
#[inline]
unsafe fn to_int_unchecked(self) -> u32 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u64> for f32 {
#[inline]
unsafe fn to_int_unchecked(self) -> u64 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u128> for f32 {
#[inline]
unsafe fn to_int_unchecked(self) -> u128 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<usize> for f32 {
#[inline]
unsafe fn to_int_unchecked(self) -> usize {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i8> for f32 {
#[inline]
unsafe fn to_int_unchecked(self) -> i8 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i16> for f32 {
#[inline]
unsafe fn to_int_unchecked(self) -> i16 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i32> for f32 {
#[inline]
unsafe fn to_int_unchecked(self) -> i32 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i64> for f32 {
#[inline]
unsafe fn to_int_unchecked(self) -> i64 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i128> for f32 {
#[inline]
unsafe fn to_int_unchecked(self) -> i128 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<isize> for f32 {
#[inline]
unsafe fn to_int_unchecked(self) -> isize {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}impl_float_to_int!(f32 => u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
39#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl private::Sealed for f64 { }
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u8> for f64 {
#[inline]
unsafe fn to_int_unchecked(self) -> u8 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u16> for f64 {
#[inline]
unsafe fn to_int_unchecked(self) -> u16 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u32> for f64 {
#[inline]
unsafe fn to_int_unchecked(self) -> u32 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u64> for f64 {
#[inline]
unsafe fn to_int_unchecked(self) -> u64 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u128> for f64 {
#[inline]
unsafe fn to_int_unchecked(self) -> u128 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<usize> for f64 {
#[inline]
unsafe fn to_int_unchecked(self) -> usize {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i8> for f64 {
#[inline]
unsafe fn to_int_unchecked(self) -> i8 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i16> for f64 {
#[inline]
unsafe fn to_int_unchecked(self) -> i16 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i32> for f64 {
#[inline]
unsafe fn to_int_unchecked(self) -> i32 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i64> for f64 {
#[inline]
unsafe fn to_int_unchecked(self) -> i64 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i128> for f64 {
#[inline]
unsafe fn to_int_unchecked(self) -> i128 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<isize> for f64 {
#[inline]
unsafe fn to_int_unchecked(self) -> isize {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}impl_float_to_int!(f64 => u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
40#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl private::Sealed for f128 { }
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u8> for f128 {
#[inline]
unsafe fn to_int_unchecked(self) -> u8 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u16> for f128 {
#[inline]
unsafe fn to_int_unchecked(self) -> u16 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u32> for f128 {
#[inline]
unsafe fn to_int_unchecked(self) -> u32 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u64> for f128 {
#[inline]
unsafe fn to_int_unchecked(self) -> u64 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u128> for f128 {
#[inline]
unsafe fn to_int_unchecked(self) -> u128 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<usize> for f128 {
#[inline]
unsafe fn to_int_unchecked(self) -> usize {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i8> for f128 {
#[inline]
unsafe fn to_int_unchecked(self) -> i8 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i16> for f128 {
#[inline]
unsafe fn to_int_unchecked(self) -> i16 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i32> for f128 {
#[inline]
unsafe fn to_int_unchecked(self) -> i32 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i64> for f128 {
#[inline]
unsafe fn to_int_unchecked(self) -> i64 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i128> for f128 {
#[inline]
unsafe fn to_int_unchecked(self) -> i128 {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<isize> for f128 {
#[inline]
unsafe fn to_int_unchecked(self) -> isize {
unsafe { crate::intrinsics::float_to_int_unchecked(self) }
}
}impl_float_to_int!(f128 => u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
41
42macro_rules! impl_from_bool {
44 ($($int:ty)*) => {$(
45 #[stable(feature = "from_bool", since = "1.28.0")]
46 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
47 impl const From<bool> for $int {
48 #[doc = concat!("[`", stringify!($int), "`]")]
50 #[doc = concat!("assert_eq!(", stringify!($int), "::from(false), 0);")]
56 #[doc = concat!("assert_eq!(", stringify!($int), "::from(true), 1);")]
58 #[inline(always)]
60 fn from(b: bool) -> Self {
61 b as Self
62 }
63 }
64 )*}
65}
66
67#[stable(feature = "from_bool", since = "1.28.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<bool> for usize {
#[doc = "[`usize`]"]
#[doc = "assert_eq!(usize::from(false), 0);"]
#[doc = "assert_eq!(usize::from(true), 1);"]
#[inline(always)]
fn from(b: bool) -> Self { b as Self }
}impl_from_bool!(u8 u16 u32 u64 u128 usize);
69#[stable(feature = "from_bool", since = "1.28.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<bool> for isize {
#[doc = "[`isize`]"]
#[doc = "assert_eq!(isize::from(false), 0);"]
#[doc = "assert_eq!(isize::from(true), 1);"]
#[inline(always)]
fn from(b: bool) -> Self { b as Self }
}impl_from_bool!(i8 i16 i32 i64 i128 isize);
70
71macro_rules! impl_from {
73 ($small:ty => $large:ty, $(#[$attrs:meta]),+) => {
74 $(#[$attrs])+
75 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
76 impl const From<$small> for $large {
77 #[doc = concat!("Converts from [`", stringify!($small), "`] to [`", stringify!($large), "`] losslessly.")]
78 #[inline(always)]
79 fn from(small: $small) -> Self {
80 debug_assert!(<$large>::MIN as i128 <= <$small>::MIN as i128);
81 debug_assert!(<$small>::MAX as u128 <= <$large>::MAX as u128);
82 small as Self
83 }
84 }
85 }
86}
87
88#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for u16 {
#[doc = "Converts from [`u8`] to [`u16`] losslessly."]
#[inline(always)]
fn from(small: u8) -> Self {
if true {
if !(<u16>::MIN as i128 <= <u8>::MIN as i128) {
crate::panicking::panic("assertion failed: <u16>::MIN as i128 <= <u8>::MIN as i128")
};
};
if true {
if !(<u8>::MAX as u128 <= <u16>::MAX as u128) {
crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <u16>::MAX as u128")
};
};
small as Self
}
}impl_from!(u8 => u16, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
90#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for u32 {
#[doc = "Converts from [`u8`] to [`u32`] losslessly."]
#[inline(always)]
fn from(small: u8) -> Self {
if true {
if !(<u32>::MIN as i128 <= <u8>::MIN as i128) {
crate::panicking::panic("assertion failed: <u32>::MIN as i128 <= <u8>::MIN as i128")
};
};
if true {
if !(<u8>::MAX as u128 <= <u32>::MAX as u128) {
crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <u32>::MAX as u128")
};
};
small as Self
}
}impl_from!(u8 => u32, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
91#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for u64 {
#[doc = "Converts from [`u8`] to [`u64`] losslessly."]
#[inline(always)]
fn from(small: u8) -> Self {
if true {
if !(<u64>::MIN as i128 <= <u8>::MIN as i128) {
crate::panicking::panic("assertion failed: <u64>::MIN as i128 <= <u8>::MIN as i128")
};
};
if true {
if !(<u8>::MAX as u128 <= <u64>::MAX as u128) {
crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <u64>::MAX as u128")
};
};
small as Self
}
}impl_from!(u8 => u64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
92#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for u128 {
#[doc = "Converts from [`u8`] to [`u128`] losslessly."]
#[inline(always)]
fn from(small: u8) -> Self {
if true {
if !(<u128>::MIN as i128 <= <u8>::MIN as i128) {
crate::panicking::panic("assertion failed: <u128>::MIN as i128 <= <u8>::MIN as i128")
};
};
if true {
if !(<u8>::MAX as u128 <= <u128>::MAX as u128) {
crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <u128>::MAX as u128")
};
};
small as Self
}
}impl_from!(u8 => u128, #[stable(feature = "i128", since = "1.26.0")]);
93#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for usize {
#[doc = "Converts from [`u8`] to [`usize`] losslessly."]
#[inline(always)]
fn from(small: u8) -> Self {
if true {
if !(<usize>::MIN as i128 <= <u8>::MIN as i128) {
crate::panicking::panic("assertion failed: <usize>::MIN as i128 <= <u8>::MIN as i128")
};
};
if true {
if !(<u8>::MAX as u128 <= <usize>::MAX as u128) {
crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <usize>::MAX as u128")
};
};
small as Self
}
}impl_from!(u8 => usize, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
94#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u16> for u32 {
#[doc = "Converts from [`u16`] to [`u32`] losslessly."]
#[inline(always)]
fn from(small: u16) -> Self {
if true {
if !(<u32>::MIN as i128 <= <u16>::MIN as i128) {
crate::panicking::panic("assertion failed: <u32>::MIN as i128 <= <u16>::MIN as i128")
};
};
if true {
if !(<u16>::MAX as u128 <= <u32>::MAX as u128) {
crate::panicking::panic("assertion failed: <u16>::MAX as u128 <= <u32>::MAX as u128")
};
};
small as Self
}
}impl_from!(u16 => u32, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
95#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u16> for u64 {
#[doc = "Converts from [`u16`] to [`u64`] losslessly."]
#[inline(always)]
fn from(small: u16) -> Self {
if true {
if !(<u64>::MIN as i128 <= <u16>::MIN as i128) {
crate::panicking::panic("assertion failed: <u64>::MIN as i128 <= <u16>::MIN as i128")
};
};
if true {
if !(<u16>::MAX as u128 <= <u64>::MAX as u128) {
crate::panicking::panic("assertion failed: <u16>::MAX as u128 <= <u64>::MAX as u128")
};
};
small as Self
}
}impl_from!(u16 => u64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
96#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u16> for u128 {
#[doc = "Converts from [`u16`] to [`u128`] losslessly."]
#[inline(always)]
fn from(small: u16) -> Self {
if true {
if !(<u128>::MIN as i128 <= <u16>::MIN as i128) {
crate::panicking::panic("assertion failed: <u128>::MIN as i128 <= <u16>::MIN as i128")
};
};
if true {
if !(<u16>::MAX as u128 <= <u128>::MAX as u128) {
crate::panicking::panic("assertion failed: <u16>::MAX as u128 <= <u128>::MAX as u128")
};
};
small as Self
}
}impl_from!(u16 => u128, #[stable(feature = "i128", since = "1.26.0")]);
97#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u32> for u64 {
#[doc = "Converts from [`u32`] to [`u64`] losslessly."]
#[inline(always)]
fn from(small: u32) -> Self {
if true {
if !(<u64>::MIN as i128 <= <u32>::MIN as i128) {
crate::panicking::panic("assertion failed: <u64>::MIN as i128 <= <u32>::MIN as i128")
};
};
if true {
if !(<u32>::MAX as u128 <= <u64>::MAX as u128) {
crate::panicking::panic("assertion failed: <u32>::MAX as u128 <= <u64>::MAX as u128")
};
};
small as Self
}
}impl_from!(u32 => u64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
98#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u32> for u128 {
#[doc = "Converts from [`u32`] to [`u128`] losslessly."]
#[inline(always)]
fn from(small: u32) -> Self {
if true {
if !(<u128>::MIN as i128 <= <u32>::MIN as i128) {
crate::panicking::panic("assertion failed: <u128>::MIN as i128 <= <u32>::MIN as i128")
};
};
if true {
if !(<u32>::MAX as u128 <= <u128>::MAX as u128) {
crate::panicking::panic("assertion failed: <u32>::MAX as u128 <= <u128>::MAX as u128")
};
};
small as Self
}
}impl_from!(u32 => u128, #[stable(feature = "i128", since = "1.26.0")]);
99#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u64> for u128 {
#[doc = "Converts from [`u64`] to [`u128`] losslessly."]
#[inline(always)]
fn from(small: u64) -> Self {
if true {
if !(<u128>::MIN as i128 <= <u64>::MIN as i128) {
crate::panicking::panic("assertion failed: <u128>::MIN as i128 <= <u64>::MIN as i128")
};
};
if true {
if !(<u64>::MAX as u128 <= <u128>::MAX as u128) {
crate::panicking::panic("assertion failed: <u64>::MAX as u128 <= <u128>::MAX as u128")
};
};
small as Self
}
}impl_from!(u64 => u128, #[stable(feature = "i128", since = "1.26.0")]);
100
101#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i8> for i16 {
#[doc = "Converts from [`i8`] to [`i16`] losslessly."]
#[inline(always)]
fn from(small: i8) -> Self {
if true {
if !(<i16>::MIN as i128 <= <i8>::MIN as i128) {
crate::panicking::panic("assertion failed: <i16>::MIN as i128 <= <i8>::MIN as i128")
};
};
if true {
if !(<i8>::MAX as u128 <= <i16>::MAX as u128) {
crate::panicking::panic("assertion failed: <i8>::MAX as u128 <= <i16>::MAX as u128")
};
};
small as Self
}
}impl_from!(i8 => i16, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
103#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i8> for i32 {
#[doc = "Converts from [`i8`] to [`i32`] losslessly."]
#[inline(always)]
fn from(small: i8) -> Self {
if true {
if !(<i32>::MIN as i128 <= <i8>::MIN as i128) {
crate::panicking::panic("assertion failed: <i32>::MIN as i128 <= <i8>::MIN as i128")
};
};
if true {
if !(<i8>::MAX as u128 <= <i32>::MAX as u128) {
crate::panicking::panic("assertion failed: <i8>::MAX as u128 <= <i32>::MAX as u128")
};
};
small as Self
}
}impl_from!(i8 => i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
104#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i8> for i64 {
#[doc = "Converts from [`i8`] to [`i64`] losslessly."]
#[inline(always)]
fn from(small: i8) -> Self {
if true {
if !(<i64>::MIN as i128 <= <i8>::MIN as i128) {
crate::panicking::panic("assertion failed: <i64>::MIN as i128 <= <i8>::MIN as i128")
};
};
if true {
if !(<i8>::MAX as u128 <= <i64>::MAX as u128) {
crate::panicking::panic("assertion failed: <i8>::MAX as u128 <= <i64>::MAX as u128")
};
};
small as Self
}
}impl_from!(i8 => i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
105#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i8> for i128 {
#[doc = "Converts from [`i8`] to [`i128`] losslessly."]
#[inline(always)]
fn from(small: i8) -> Self {
if true {
if !(<i128>::MIN as i128 <= <i8>::MIN as i128) {
crate::panicking::panic("assertion failed: <i128>::MIN as i128 <= <i8>::MIN as i128")
};
};
if true {
if !(<i8>::MAX as u128 <= <i128>::MAX as u128) {
crate::panicking::panic("assertion failed: <i8>::MAX as u128 <= <i128>::MAX as u128")
};
};
small as Self
}
}impl_from!(i8 => i128, #[stable(feature = "i128", since = "1.26.0")]);
106#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i8> for isize {
#[doc = "Converts from [`i8`] to [`isize`] losslessly."]
#[inline(always)]
fn from(small: i8) -> Self {
if true {
if !(<isize>::MIN as i128 <= <i8>::MIN as i128) {
crate::panicking::panic("assertion failed: <isize>::MIN as i128 <= <i8>::MIN as i128")
};
};
if true {
if !(<i8>::MAX as u128 <= <isize>::MAX as u128) {
crate::panicking::panic("assertion failed: <i8>::MAX as u128 <= <isize>::MAX as u128")
};
};
small as Self
}
}impl_from!(i8 => isize, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
107#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i16> for i32 {
#[doc = "Converts from [`i16`] to [`i32`] losslessly."]
#[inline(always)]
fn from(small: i16) -> Self {
if true {
if !(<i32>::MIN as i128 <= <i16>::MIN as i128) {
crate::panicking::panic("assertion failed: <i32>::MIN as i128 <= <i16>::MIN as i128")
};
};
if true {
if !(<i16>::MAX as u128 <= <i32>::MAX as u128) {
crate::panicking::panic("assertion failed: <i16>::MAX as u128 <= <i32>::MAX as u128")
};
};
small as Self
}
}impl_from!(i16 => i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
108#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i16> for i64 {
#[doc = "Converts from [`i16`] to [`i64`] losslessly."]
#[inline(always)]
fn from(small: i16) -> Self {
if true {
if !(<i64>::MIN as i128 <= <i16>::MIN as i128) {
crate::panicking::panic("assertion failed: <i64>::MIN as i128 <= <i16>::MIN as i128")
};
};
if true {
if !(<i16>::MAX as u128 <= <i64>::MAX as u128) {
crate::panicking::panic("assertion failed: <i16>::MAX as u128 <= <i64>::MAX as u128")
};
};
small as Self
}
}impl_from!(i16 => i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
109#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i16> for i128 {
#[doc = "Converts from [`i16`] to [`i128`] losslessly."]
#[inline(always)]
fn from(small: i16) -> Self {
if true {
if !(<i128>::MIN as i128 <= <i16>::MIN as i128) {
crate::panicking::panic("assertion failed: <i128>::MIN as i128 <= <i16>::MIN as i128")
};
};
if true {
if !(<i16>::MAX as u128 <= <i128>::MAX as u128) {
crate::panicking::panic("assertion failed: <i16>::MAX as u128 <= <i128>::MAX as u128")
};
};
small as Self
}
}impl_from!(i16 => i128, #[stable(feature = "i128", since = "1.26.0")]);
110#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i32> for i64 {
#[doc = "Converts from [`i32`] to [`i64`] losslessly."]
#[inline(always)]
fn from(small: i32) -> Self {
if true {
if !(<i64>::MIN as i128 <= <i32>::MIN as i128) {
crate::panicking::panic("assertion failed: <i64>::MIN as i128 <= <i32>::MIN as i128")
};
};
if true {
if !(<i32>::MAX as u128 <= <i64>::MAX as u128) {
crate::panicking::panic("assertion failed: <i32>::MAX as u128 <= <i64>::MAX as u128")
};
};
small as Self
}
}impl_from!(i32 => i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
111#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i32> for i128 {
#[doc = "Converts from [`i32`] to [`i128`] losslessly."]
#[inline(always)]
fn from(small: i32) -> Self {
if true {
if !(<i128>::MIN as i128 <= <i32>::MIN as i128) {
crate::panicking::panic("assertion failed: <i128>::MIN as i128 <= <i32>::MIN as i128")
};
};
if true {
if !(<i32>::MAX as u128 <= <i128>::MAX as u128) {
crate::panicking::panic("assertion failed: <i32>::MAX as u128 <= <i128>::MAX as u128")
};
};
small as Self
}
}impl_from!(i32 => i128, #[stable(feature = "i128", since = "1.26.0")]);
112#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i64> for i128 {
#[doc = "Converts from [`i64`] to [`i128`] losslessly."]
#[inline(always)]
fn from(small: i64) -> Self {
if true {
if !(<i128>::MIN as i128 <= <i64>::MIN as i128) {
crate::panicking::panic("assertion failed: <i128>::MIN as i128 <= <i64>::MIN as i128")
};
};
if true {
if !(<i64>::MAX as u128 <= <i128>::MAX as u128) {
crate::panicking::panic("assertion failed: <i64>::MAX as u128 <= <i128>::MAX as u128")
};
};
small as Self
}
}impl_from!(i64 => i128, #[stable(feature = "i128", since = "1.26.0")]);
113
114#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for i16 {
#[doc = "Converts from [`u8`] to [`i16`] losslessly."]
#[inline(always)]
fn from(small: u8) -> Self {
if true {
if !(<i16>::MIN as i128 <= <u8>::MIN as i128) {
crate::panicking::panic("assertion failed: <i16>::MIN as i128 <= <u8>::MIN as i128")
};
};
if true {
if !(<u8>::MAX as u128 <= <i16>::MAX as u128) {
crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <i16>::MAX as u128")
};
};
small as Self
}
}impl_from!(u8 => i16, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
116#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for i32 {
#[doc = "Converts from [`u8`] to [`i32`] losslessly."]
#[inline(always)]
fn from(small: u8) -> Self {
if true {
if !(<i32>::MIN as i128 <= <u8>::MIN as i128) {
crate::panicking::panic("assertion failed: <i32>::MIN as i128 <= <u8>::MIN as i128")
};
};
if true {
if !(<u8>::MAX as u128 <= <i32>::MAX as u128) {
crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <i32>::MAX as u128")
};
};
small as Self
}
}impl_from!(u8 => i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
117#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for i64 {
#[doc = "Converts from [`u8`] to [`i64`] losslessly."]
#[inline(always)]
fn from(small: u8) -> Self {
if true {
if !(<i64>::MIN as i128 <= <u8>::MIN as i128) {
crate::panicking::panic("assertion failed: <i64>::MIN as i128 <= <u8>::MIN as i128")
};
};
if true {
if !(<u8>::MAX as u128 <= <i64>::MAX as u128) {
crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <i64>::MAX as u128")
};
};
small as Self
}
}impl_from!(u8 => i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
118#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for i128 {
#[doc = "Converts from [`u8`] to [`i128`] losslessly."]
#[inline(always)]
fn from(small: u8) -> Self {
if true {
if !(<i128>::MIN as i128 <= <u8>::MIN as i128) {
crate::panicking::panic("assertion failed: <i128>::MIN as i128 <= <u8>::MIN as i128")
};
};
if true {
if !(<u8>::MAX as u128 <= <i128>::MAX as u128) {
crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <i128>::MAX as u128")
};
};
small as Self
}
}impl_from!(u8 => i128, #[stable(feature = "i128", since = "1.26.0")]);
119#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u16> for i32 {
#[doc = "Converts from [`u16`] to [`i32`] losslessly."]
#[inline(always)]
fn from(small: u16) -> Self {
if true {
if !(<i32>::MIN as i128 <= <u16>::MIN as i128) {
crate::panicking::panic("assertion failed: <i32>::MIN as i128 <= <u16>::MIN as i128")
};
};
if true {
if !(<u16>::MAX as u128 <= <i32>::MAX as u128) {
crate::panicking::panic("assertion failed: <u16>::MAX as u128 <= <i32>::MAX as u128")
};
};
small as Self
}
}impl_from!(u16 => i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
120#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u16> for i64 {
#[doc = "Converts from [`u16`] to [`i64`] losslessly."]
#[inline(always)]
fn from(small: u16) -> Self {
if true {
if !(<i64>::MIN as i128 <= <u16>::MIN as i128) {
crate::panicking::panic("assertion failed: <i64>::MIN as i128 <= <u16>::MIN as i128")
};
};
if true {
if !(<u16>::MAX as u128 <= <i64>::MAX as u128) {
crate::panicking::panic("assertion failed: <u16>::MAX as u128 <= <i64>::MAX as u128")
};
};
small as Self
}
}impl_from!(u16 => i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
121#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u16> for i128 {
#[doc = "Converts from [`u16`] to [`i128`] losslessly."]
#[inline(always)]
fn from(small: u16) -> Self {
if true {
if !(<i128>::MIN as i128 <= <u16>::MIN as i128) {
crate::panicking::panic("assertion failed: <i128>::MIN as i128 <= <u16>::MIN as i128")
};
};
if true {
if !(<u16>::MAX as u128 <= <i128>::MAX as u128) {
crate::panicking::panic("assertion failed: <u16>::MAX as u128 <= <i128>::MAX as u128")
};
};
small as Self
}
}impl_from!(u16 => i128, #[stable(feature = "i128", since = "1.26.0")]);
122#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u32> for i64 {
#[doc = "Converts from [`u32`] to [`i64`] losslessly."]
#[inline(always)]
fn from(small: u32) -> Self {
if true {
if !(<i64>::MIN as i128 <= <u32>::MIN as i128) {
crate::panicking::panic("assertion failed: <i64>::MIN as i128 <= <u32>::MIN as i128")
};
};
if true {
if !(<u32>::MAX as u128 <= <i64>::MAX as u128) {
crate::panicking::panic("assertion failed: <u32>::MAX as u128 <= <i64>::MAX as u128")
};
};
small as Self
}
}impl_from!(u32 => i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
123#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u32> for i128 {
#[doc = "Converts from [`u32`] to [`i128`] losslessly."]
#[inline(always)]
fn from(small: u32) -> Self {
if true {
if !(<i128>::MIN as i128 <= <u32>::MIN as i128) {
crate::panicking::panic("assertion failed: <i128>::MIN as i128 <= <u32>::MIN as i128")
};
};
if true {
if !(<u32>::MAX as u128 <= <i128>::MAX as u128) {
crate::panicking::panic("assertion failed: <u32>::MAX as u128 <= <i128>::MAX as u128")
};
};
small as Self
}
}impl_from!(u32 => i128, #[stable(feature = "i128", since = "1.26.0")]);
124#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u64> for i128 {
#[doc = "Converts from [`u64`] to [`i128`] losslessly."]
#[inline(always)]
fn from(small: u64) -> Self {
if true {
if !(<i128>::MIN as i128 <= <u64>::MIN as i128) {
crate::panicking::panic("assertion failed: <i128>::MIN as i128 <= <u64>::MIN as i128")
};
};
if true {
if !(<u64>::MAX as u128 <= <i128>::MAX as u128) {
crate::panicking::panic("assertion failed: <u64>::MAX as u128 <= <i128>::MAX as u128")
};
};
small as Self
}
}impl_from!(u64 => i128, #[stable(feature = "i128", since = "1.26.0")]);
125
126#[stable(feature = "lossless_iusize_conv", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u16> for usize {
#[doc = "Converts from [`u16`] to [`usize`] losslessly."]
#[inline(always)]
fn from(small: u16) -> Self {
if true {
if !(<usize>::MIN as i128 <= <u16>::MIN as i128) {
crate::panicking::panic("assertion failed: <usize>::MIN as i128 <= <u16>::MIN as i128")
};
};
if true {
if !(<u16>::MAX as u128 <= <usize>::MAX as u128) {
crate::panicking::panic("assertion failed: <u16>::MAX as u128 <= <usize>::MAX as u128")
};
};
small as Self
}
}impl_from!(u16 => usize, #[stable(feature = "lossless_iusize_conv", since = "1.26.0")]);
130#[stable(feature = "lossless_iusize_conv", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for isize {
#[doc = "Converts from [`u8`] to [`isize`] losslessly."]
#[inline(always)]
fn from(small: u8) -> Self {
if true {
if !(<isize>::MIN as i128 <= <u8>::MIN as i128) {
crate::panicking::panic("assertion failed: <isize>::MIN as i128 <= <u8>::MIN as i128")
};
};
if true {
if !(<u8>::MAX as u128 <= <isize>::MAX as u128) {
crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <isize>::MAX as u128")
};
};
small as Self
}
}impl_from!(u8 => isize, #[stable(feature = "lossless_iusize_conv", since = "1.26.0")]);
131#[stable(feature = "lossless_iusize_conv", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i16> for isize {
#[doc = "Converts from [`i16`] to [`isize`] losslessly."]
#[inline(always)]
fn from(small: i16) -> Self {
if true {
if !(<isize>::MIN as i128 <= <i16>::MIN as i128) {
crate::panicking::panic("assertion failed: <isize>::MIN as i128 <= <i16>::MIN as i128")
};
};
if true {
if !(<i16>::MAX as u128 <= <isize>::MAX as u128) {
crate::panicking::panic("assertion failed: <i16>::MAX as u128 <= <isize>::MAX as u128")
};
};
small as Self
}
}impl_from!(i16 => isize, #[stable(feature = "lossless_iusize_conv", since = "1.26.0")]);
132
133#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i8> for f16 {
#[doc = "Converts from [`i8`] to [`f16`] losslessly."]
#[inline(always)]
fn from(small: i8) -> Self {
if true {
if !(<f16>::MIN as i128 <= <i8>::MIN as i128) {
crate::panicking::panic("assertion failed: <f16>::MIN as i128 <= <i8>::MIN as i128")
};
};
if true {
if !(<i8>::MAX as u128 <= <f16>::MAX as u128) {
crate::panicking::panic("assertion failed: <i8>::MAX as u128 <= <f16>::MAX as u128")
};
};
small as Self
}
}impl_from!(i8 => f16, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
152#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i8> for f32 {
#[doc = "Converts from [`i8`] to [`f32`] losslessly."]
#[inline(always)]
fn from(small: i8) -> Self {
if true {
if !(<f32>::MIN as i128 <= <i8>::MIN as i128) {
crate::panicking::panic("assertion failed: <f32>::MIN as i128 <= <i8>::MIN as i128")
};
};
if true {
if !(<i8>::MAX as u128 <= <f32>::MAX as u128) {
crate::panicking::panic("assertion failed: <i8>::MAX as u128 <= <f32>::MAX as u128")
};
};
small as Self
}
}impl_from!(i8 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
153#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i8> for f64 {
#[doc = "Converts from [`i8`] to [`f64`] losslessly."]
#[inline(always)]
fn from(small: i8) -> Self {
if true {
if !(<f64>::MIN as i128 <= <i8>::MIN as i128) {
crate::panicking::panic("assertion failed: <f64>::MIN as i128 <= <i8>::MIN as i128")
};
};
if true {
if !(<i8>::MAX as u128 <= <f64>::MAX as u128) {
crate::panicking::panic("assertion failed: <i8>::MAX as u128 <= <f64>::MAX as u128")
};
};
small as Self
}
}impl_from!(i8 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
154#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i8> for f128 {
#[doc = "Converts from [`i8`] to [`f128`] losslessly."]
#[inline(always)]
fn from(small: i8) -> Self {
if true {
if !(<f128>::MIN as i128 <= <i8>::MIN as i128) {
crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <i8>::MIN as i128")
};
};
if true {
if !(<i8>::MAX as u128 <= <f128>::MAX as u128) {
crate::panicking::panic("assertion failed: <i8>::MAX as u128 <= <f128>::MAX as u128")
};
};
small as Self
}
}impl_from!(i8 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
155#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i16> for f32 {
#[doc = "Converts from [`i16`] to [`f32`] losslessly."]
#[inline(always)]
fn from(small: i16) -> Self {
if true {
if !(<f32>::MIN as i128 <= <i16>::MIN as i128) {
crate::panicking::panic("assertion failed: <f32>::MIN as i128 <= <i16>::MIN as i128")
};
};
if true {
if !(<i16>::MAX as u128 <= <f32>::MAX as u128) {
crate::panicking::panic("assertion failed: <i16>::MAX as u128 <= <f32>::MAX as u128")
};
};
small as Self
}
}impl_from!(i16 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
156#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i16> for f64 {
#[doc = "Converts from [`i16`] to [`f64`] losslessly."]
#[inline(always)]
fn from(small: i16) -> Self {
if true {
if !(<f64>::MIN as i128 <= <i16>::MIN as i128) {
crate::panicking::panic("assertion failed: <f64>::MIN as i128 <= <i16>::MIN as i128")
};
};
if true {
if !(<i16>::MAX as u128 <= <f64>::MAX as u128) {
crate::panicking::panic("assertion failed: <i16>::MAX as u128 <= <f64>::MAX as u128")
};
};
small as Self
}
}impl_from!(i16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
157#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i16> for f128 {
#[doc = "Converts from [`i16`] to [`f128`] losslessly."]
#[inline(always)]
fn from(small: i16) -> Self {
if true {
if !(<f128>::MIN as i128 <= <i16>::MIN as i128) {
crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <i16>::MIN as i128")
};
};
if true {
if !(<i16>::MAX as u128 <= <f128>::MAX as u128) {
crate::panicking::panic("assertion failed: <i16>::MAX as u128 <= <f128>::MAX as u128")
};
};
small as Self
}
}impl_from!(i16 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
158#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i32> for f64 {
#[doc = "Converts from [`i32`] to [`f64`] losslessly."]
#[inline(always)]
fn from(small: i32) -> Self {
if true {
if !(<f64>::MIN as i128 <= <i32>::MIN as i128) {
crate::panicking::panic("assertion failed: <f64>::MIN as i128 <= <i32>::MIN as i128")
};
};
if true {
if !(<i32>::MAX as u128 <= <f64>::MAX as u128) {
crate::panicking::panic("assertion failed: <i32>::MAX as u128 <= <f64>::MAX as u128")
};
};
small as Self
}
}impl_from!(i32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
159#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i32> for f128 {
#[doc = "Converts from [`i32`] to [`f128`] losslessly."]
#[inline(always)]
fn from(small: i32) -> Self {
if true {
if !(<f128>::MIN as i128 <= <i32>::MIN as i128) {
crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <i32>::MIN as i128")
};
};
if true {
if !(<i32>::MAX as u128 <= <f128>::MAX as u128) {
crate::panicking::panic("assertion failed: <i32>::MAX as u128 <= <f128>::MAX as u128")
};
};
small as Self
}
}impl_from!(i32 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
160#[unstable(feature = "f128", issue = "116909")]
#[unstable_feature_bound(f128)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i64> for f128 {
#[doc = "Converts from [`i64`] to [`f128`] losslessly."]
#[inline(always)]
fn from(small: i64) -> Self {
if true {
if !(<f128>::MIN as i128 <= <i64>::MIN as i128) {
crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <i64>::MIN as i128")
};
};
if true {
if !(<i64>::MAX as u128 <= <f128>::MAX as u128) {
crate::panicking::panic("assertion failed: <i64>::MAX as u128 <= <f128>::MAX as u128")
};
};
small as Self
}
}impl_from!(i64 => f128, #[unstable(feature = "f128", issue = "116909")], #[unstable_feature_bound(f128)]);
161
162#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for f16 {
#[doc = "Converts from [`u8`] to [`f16`] losslessly."]
#[inline(always)]
fn from(small: u8) -> Self {
if true {
if !(<f16>::MIN as i128 <= <u8>::MIN as i128) {
crate::panicking::panic("assertion failed: <f16>::MIN as i128 <= <u8>::MIN as i128")
};
};
if true {
if !(<u8>::MAX as u128 <= <f16>::MAX as u128) {
crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <f16>::MAX as u128")
};
};
small as Self
}
}impl_from!(u8 => f16, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
164#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for f32 {
#[doc = "Converts from [`u8`] to [`f32`] losslessly."]
#[inline(always)]
fn from(small: u8) -> Self {
if true {
if !(<f32>::MIN as i128 <= <u8>::MIN as i128) {
crate::panicking::panic("assertion failed: <f32>::MIN as i128 <= <u8>::MIN as i128")
};
};
if true {
if !(<u8>::MAX as u128 <= <f32>::MAX as u128) {
crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <f32>::MAX as u128")
};
};
small as Self
}
}impl_from!(u8 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
165#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for f64 {
#[doc = "Converts from [`u8`] to [`f64`] losslessly."]
#[inline(always)]
fn from(small: u8) -> Self {
if true {
if !(<f64>::MIN as i128 <= <u8>::MIN as i128) {
crate::panicking::panic("assertion failed: <f64>::MIN as i128 <= <u8>::MIN as i128")
};
};
if true {
if !(<u8>::MAX as u128 <= <f64>::MAX as u128) {
crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <f64>::MAX as u128")
};
};
small as Self
}
}impl_from!(u8 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
166#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for f128 {
#[doc = "Converts from [`u8`] to [`f128`] losslessly."]
#[inline(always)]
fn from(small: u8) -> Self {
if true {
if !(<f128>::MIN as i128 <= <u8>::MIN as i128) {
crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <u8>::MIN as i128")
};
};
if true {
if !(<u8>::MAX as u128 <= <f128>::MAX as u128) {
crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <f128>::MAX as u128")
};
};
small as Self
}
}impl_from!(u8 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
167#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u16> for f32 {
#[doc = "Converts from [`u16`] to [`f32`] losslessly."]
#[inline(always)]
fn from(small: u16) -> Self {
if true {
if !(<f32>::MIN as i128 <= <u16>::MIN as i128) {
crate::panicking::panic("assertion failed: <f32>::MIN as i128 <= <u16>::MIN as i128")
};
};
if true {
if !(<u16>::MAX as u128 <= <f32>::MAX as u128) {
crate::panicking::panic("assertion failed: <u16>::MAX as u128 <= <f32>::MAX as u128")
};
};
small as Self
}
}impl_from!(u16 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
168#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u16> for f64 {
#[doc = "Converts from [`u16`] to [`f64`] losslessly."]
#[inline(always)]
fn from(small: u16) -> Self {
if true {
if !(<f64>::MIN as i128 <= <u16>::MIN as i128) {
crate::panicking::panic("assertion failed: <f64>::MIN as i128 <= <u16>::MIN as i128")
};
};
if true {
if !(<u16>::MAX as u128 <= <f64>::MAX as u128) {
crate::panicking::panic("assertion failed: <u16>::MAX as u128 <= <f64>::MAX as u128")
};
};
small as Self
}
}impl_from!(u16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
169#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u16> for f128 {
#[doc = "Converts from [`u16`] to [`f128`] losslessly."]
#[inline(always)]
fn from(small: u16) -> Self {
if true {
if !(<f128>::MIN as i128 <= <u16>::MIN as i128) {
crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <u16>::MIN as i128")
};
};
if true {
if !(<u16>::MAX as u128 <= <f128>::MAX as u128) {
crate::panicking::panic("assertion failed: <u16>::MAX as u128 <= <f128>::MAX as u128")
};
};
small as Self
}
}impl_from!(u16 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
170#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u32> for f64 {
#[doc = "Converts from [`u32`] to [`f64`] losslessly."]
#[inline(always)]
fn from(small: u32) -> Self {
if true {
if !(<f64>::MIN as i128 <= <u32>::MIN as i128) {
crate::panicking::panic("assertion failed: <f64>::MIN as i128 <= <u32>::MIN as i128")
};
};
if true {
if !(<u32>::MAX as u128 <= <f64>::MAX as u128) {
crate::panicking::panic("assertion failed: <u32>::MAX as u128 <= <f64>::MAX as u128")
};
};
small as Self
}
}impl_from!(u32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
171#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u32> for f128 {
#[doc = "Converts from [`u32`] to [`f128`] losslessly."]
#[inline(always)]
fn from(small: u32) -> Self {
if true {
if !(<f128>::MIN as i128 <= <u32>::MIN as i128) {
crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <u32>::MIN as i128")
};
};
if true {
if !(<u32>::MAX as u128 <= <f128>::MAX as u128) {
crate::panicking::panic("assertion failed: <u32>::MAX as u128 <= <f128>::MAX as u128")
};
};
small as Self
}
}impl_from!(u32 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
172#[unstable(feature = "f128", issue = "116909")]
#[unstable_feature_bound(f128)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u64> for f128 {
#[doc = "Converts from [`u64`] to [`f128`] losslessly."]
#[inline(always)]
fn from(small: u64) -> Self {
if true {
if !(<f128>::MIN as i128 <= <u64>::MIN as i128) {
crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <u64>::MIN as i128")
};
};
if true {
if !(<u64>::MAX as u128 <= <f128>::MAX as u128) {
crate::panicking::panic("assertion failed: <u64>::MAX as u128 <= <f128>::MAX as u128")
};
};
small as Self
}
}impl_from!(u64 => f128, #[unstable(feature = "f128", issue = "116909")], #[unstable_feature_bound(f128)]);
173
174#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<f16> for f64 {
#[doc = "Converts from [`f16`] to [`f64`] losslessly."]
#[inline(always)]
fn from(small: f16) -> Self {
if true {
if !(<f64>::MIN as i128 <= <f16>::MIN as i128) {
crate::panicking::panic("assertion failed: <f64>::MIN as i128 <= <f16>::MIN as i128")
};
};
if true {
if !(<f16>::MAX as u128 <= <f64>::MAX as u128) {
crate::panicking::panic("assertion failed: <f16>::MAX as u128 <= <f64>::MAX as u128")
};
};
small as Self
}
}impl_from!(f16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
178#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<f16> for f128 {
#[doc = "Converts from [`f16`] to [`f128`] losslessly."]
#[inline(always)]
fn from(small: f16) -> Self {
if true {
if !(<f128>::MIN as i128 <= <f16>::MIN as i128) {
crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <f16>::MIN as i128")
};
};
if true {
if !(<f16>::MAX as u128 <= <f128>::MAX as u128) {
crate::panicking::panic("assertion failed: <f16>::MAX as u128 <= <f128>::MAX as u128")
};
};
small as Self
}
}impl_from!(f16 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
179#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<f32> for f64 {
#[doc = "Converts from [`f32`] to [`f64`] losslessly."]
#[inline(always)]
fn from(small: f32) -> Self {
if true {
if !(<f64>::MIN as i128 <= <f32>::MIN as i128) {
crate::panicking::panic("assertion failed: <f64>::MIN as i128 <= <f32>::MIN as i128")
};
};
if true {
if !(<f32>::MAX as u128 <= <f64>::MAX as u128) {
crate::panicking::panic("assertion failed: <f32>::MAX as u128 <= <f64>::MAX as u128")
};
};
small as Self
}
}impl_from!(f32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
180#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<f32> for f128 {
#[doc = "Converts from [`f32`] to [`f128`] losslessly."]
#[inline(always)]
fn from(small: f32) -> Self {
if true {
if !(<f128>::MIN as i128 <= <f32>::MIN as i128) {
crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <f32>::MIN as i128")
};
};
if true {
if !(<f32>::MAX as u128 <= <f128>::MAX as u128) {
crate::panicking::panic("assertion failed: <f32>::MAX as u128 <= <f128>::MAX as u128")
};
};
small as Self
}
}impl_from!(f32 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
181#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<f64> for f128 {
#[doc = "Converts from [`f64`] to [`f128`] losslessly."]
#[inline(always)]
fn from(small: f64) -> Self {
if true {
if !(<f128>::MIN as i128 <= <f64>::MIN as i128) {
crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <f64>::MIN as i128")
};
};
if true {
if !(<f64>::MAX as u128 <= <f128>::MAX as u128) {
crate::panicking::panic("assertion failed: <f64>::MAX as u128 <= <f128>::MAX as u128")
};
};
small as Self
}
}impl_from!(f64 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
182
183macro_rules! impl_float_from_bool {
184 (
185 $float:ty $(;
186 doctest_prefix: $(#[doc = $doctest_prefix:literal])*
187 doctest_suffix: $(#[doc = $doctest_suffix:literal])*
188 )?
189 ) => {
190 #[stable(feature = "float_from_bool", since = "1.68.0")]
191 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
192 impl const From<bool> for $float {
193 #[doc = concat!("Converts a [`bool`] to [`", stringify!($float),"`] losslessly.")]
194 $($(#[doc = $doctest_prefix])*)?
199 #[doc = concat!("let x = ", stringify!($float), "::from(false);")]
200 #[doc = concat!("let y = ", stringify!($float), "::from(true);")]
204 $($(#[doc = $doctest_suffix])*)?
206 #[inline]
208 fn from(small: bool) -> Self {
209 small as u8 as Self
210 }
211 }
212 };
213}
214
215#[stable(feature = "float_from_bool", since = "1.68.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<bool> for f16 {
#[doc = "Converts a [`bool`] to [`f16`] losslessly."]
#[doc = r"# #![allow(unused_features)]"]
#[doc = r"#![feature(f16)]"]
#[doc = r#"# #[cfg(all(target_arch = "x86_64", target_os = "linux"))] {"#]
#[doc = r""]
#[doc = "let x = f16::from(false);"]
#[doc = "let y = f16::from(true);"]
#[doc = r"# }"]
#[inline]
fn from(small: bool) -> Self { small as u8 as Self }
}impl_float_from_bool!(
217 f16;
218 doctest_prefix:
219 doctest_suffix:
225 );
227#[stable(feature = "float_from_bool", since = "1.68.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<bool> for f32 {
#[doc = "Converts a [`bool`] to [`f32`] losslessly."]
#[doc = "let x = f32::from(false);"]
#[doc = "let y = f32::from(true);"]
#[inline]
fn from(small: bool) -> Self { small as u8 as Self }
}impl_float_from_bool!(f32);
228#[stable(feature = "float_from_bool", since = "1.68.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<bool> for f64 {
#[doc = "Converts a [`bool`] to [`f64`] losslessly."]
#[doc = "let x = f64::from(false);"]
#[doc = "let y = f64::from(true);"]
#[inline]
fn from(small: bool) -> Self { small as u8 as Self }
}impl_float_from_bool!(f64);
229#[stable(feature = "float_from_bool", since = "1.68.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<bool> for f128 {
#[doc = "Converts a [`bool`] to [`f128`] losslessly."]
#[doc = r"# #![allow(unused_features)]"]
#[doc = r"#![feature(f128)]"]
#[doc = r#"# #[cfg(all(target_arch = "x86_64", target_os = "linux"))] {"#]
#[doc = r""]
#[doc = "let x = f128::from(false);"]
#[doc = "let y = f128::from(true);"]
#[doc = r"# }"]
#[inline]
fn from(small: bool) -> Self { small as u8 as Self }
}impl_float_from_bool!(
230 f128;
231 doctest_prefix:
232 doctest_suffix:
237 );
239
240macro_rules! impl_try_from_unbounded {
242 ($source:ty => $($target:ty),+) => {$(
243 #[stable(feature = "try_from", since = "1.34.0")]
244 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
245 impl const TryFrom<$source> for $target {
246 type Error = TryFromIntError;
247
248 #[inline]
252 fn try_from(value: $source) -> Result<Self, Self::Error> {
253 Ok(value as Self)
254 }
255 }
256 )*}
257}
258
259macro_rules! impl_try_from_lower_bounded {
261 ($source:ty => $($target:ty),+) => {$(
262 #[stable(feature = "try_from", since = "1.34.0")]
263 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
264 impl const TryFrom<$source> for $target {
265 type Error = TryFromIntError;
266
267 #[inline]
271 fn try_from(u: $source) -> Result<Self, Self::Error> {
272 if u >= 0 {
273 Ok(u as Self)
274 } else {
275 Err(TryFromIntError(()))
276 }
277 }
278 }
279 )*}
280}
281
282macro_rules! impl_try_from_upper_bounded {
284 ($source:ty => $($target:ty),+) => {$(
285 #[stable(feature = "try_from", since = "1.34.0")]
286 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
287 impl const TryFrom<$source> for $target {
288 type Error = TryFromIntError;
289
290 #[inline]
294 fn try_from(u: $source) -> Result<Self, Self::Error> {
295 if u > (Self::MAX as $source) {
296 Err(TryFromIntError(()))
297 } else {
298 Ok(u as Self)
299 }
300 }
301 }
302 )*}
303}
304
305macro_rules! impl_try_from_both_bounded {
307 ($source:ty => $($target:ty),+) => {$(
308 #[stable(feature = "try_from", since = "1.34.0")]
309 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
310 impl const TryFrom<$source> for $target {
311 type Error = TryFromIntError;
312
313 #[inline]
317 fn try_from(u: $source) -> Result<Self, Self::Error> {
318 let min = Self::MIN as $source;
319 let max = Self::MAX as $source;
320 if u < min || u > max {
321 Err(TryFromIntError(()))
322 } else {
323 Ok(u as Self)
324 }
325 }
326 }
327 )*}
328}
329
330macro_rules! impl_try_from_integer_for_bool {
332 ($($int:ty)+) => {$(
333 #[stable(feature = "bool_try_from_int", since = "1.95.0")]
334 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
335 impl const TryFrom<$int> for bool {
336 type Error = TryFromIntError;
337
338 #[doc = concat!("assert_eq!(bool::try_from(0_", stringify!($int), "), Ok(false));")]
345 #[doc = concat!("assert_eq!(bool::try_from(1_", stringify!($int), "), Ok(true));")]
347 #[doc = concat!("assert!(bool::try_from(2_", stringify!($int), ").is_err());")]
349 #[inline]
351 fn try_from(i: $int) -> Result<Self, Self::Error> {
352 match i {
353 0 => Ok(false),
354 1 => Ok(true),
355 _ => Err(TryFromIntError(())),
356 }
357 }
358 }
359 )*}
360}
361
362macro_rules! rev {
363 ($mac:ident, $source:ty => $($target:ty),+) => {$(
364 $mac!($target => $source);
365 )*}
366}
367
368#[stable(feature = "bool_try_from_int", since = "1.95.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u8> for bool {
type Error = TryFromIntError;
#[doc = "assert_eq!(bool::try_from(0_u8), Ok(false));"]
#[doc = "assert_eq!(bool::try_from(1_u8), Ok(true));"]
#[doc = "assert!(bool::try_from(2_u8).is_err());"]
#[inline]
fn try_from(i: u8) -> Result<Self, Self::Error> {
match i {
0 => Ok(false),
1 => Ok(true),
_ => Err(TryFromIntError(())),
}
}
}impl_try_from_integer_for_bool!(u128 u64 u32 u16 u8);
370#[stable(feature = "bool_try_from_int", since = "1.95.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i8> for bool {
type Error = TryFromIntError;
#[doc = "assert_eq!(bool::try_from(0_i8), Ok(false));"]
#[doc = "assert_eq!(bool::try_from(1_i8), Ok(true));"]
#[doc = "assert!(bool::try_from(2_i8).is_err());"]
#[inline]
fn try_from(i: i8) -> Result<Self, Self::Error> {
match i {
0 => Ok(false),
1 => Ok(true),
_ => Err(TryFromIntError(())),
}
}
}impl_try_from_integer_for_bool!(i128 i64 i32 i16 i8);
371
372#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u16> for u8 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: u16) -> Result<Self, Self::Error> {
if u > (Self::MAX as u16) {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(u16 => u8);
374#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u32> for u16 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: u32) -> Result<Self, Self::Error> {
if u > (Self::MAX as u32) {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(u32 => u8, u16);
375#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u64> for u32 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: u64) -> Result<Self, Self::Error> {
if u > (Self::MAX as u64) {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(u64 => u8, u16, u32);
376#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u128> for u64 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: u128) -> Result<Self, Self::Error> {
if u > (Self::MAX as u128) {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(u128 => u8, u16, u32, u64);
377
378#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i16> for i8 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: i16) -> Result<Self, Self::Error> {
let min = Self::MIN as i16;
let max = Self::MAX as i16;
if u < min || u > max {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_both_bounded!(i16 => i8);
380#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i32> for i16 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: i32) -> Result<Self, Self::Error> {
let min = Self::MIN as i32;
let max = Self::MAX as i32;
if u < min || u > max {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_both_bounded!(i32 => i8, i16);
381#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i64> for i32 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: i64) -> Result<Self, Self::Error> {
let min = Self::MIN as i64;
let max = Self::MAX as i64;
if u < min || u > max {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_both_bounded!(i64 => i8, i16, i32);
382#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i128> for i64 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: i128) -> Result<Self, Self::Error> {
let min = Self::MIN as i128;
let max = Self::MAX as i128;
if u < min || u > max {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_both_bounded!(i128 => i8, i16, i32, i64);
383
384#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u8> for i8 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: u8) -> Result<Self, Self::Error> {
if u > (Self::MAX as u8) {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(u8 => i8);
386#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u16> for i16 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: u16) -> Result<Self, Self::Error> {
if u > (Self::MAX as u16) {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(u16 => i8, i16);
387#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u32> for i32 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: u32) -> Result<Self, Self::Error> {
if u > (Self::MAX as u32) {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(u32 => i8, i16, i32);
388#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u64> for i64 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: u64) -> Result<Self, Self::Error> {
if u > (Self::MAX as u64) {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(u64 => i8, i16, i32, i64);
389#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u128> for i128 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: u128) -> Result<Self, Self::Error> {
if u > (Self::MAX as u128) {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(u128 => i8, i16, i32, i64, i128);
390
391#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i8> for u128 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: i8) -> Result<Self, Self::Error> {
if u >= 0 { Ok(u as Self) } else { Err(TryFromIntError(())) }
}
}impl_try_from_lower_bounded!(i8 => u8, u16, u32, u64, u128);
393#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i16> for u8 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: i16) -> Result<Self, Self::Error> {
let min = Self::MIN as i16;
let max = Self::MAX as i16;
if u < min || u > max {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_both_bounded!(i16 => u8);
394#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i16> for u128 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: i16) -> Result<Self, Self::Error> {
if u >= 0 { Ok(u as Self) } else { Err(TryFromIntError(())) }
}
}impl_try_from_lower_bounded!(i16 => u16, u32, u64, u128);
395#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i32> for u16 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: i32) -> Result<Self, Self::Error> {
let min = Self::MIN as i32;
let max = Self::MAX as i32;
if u < min || u > max {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_both_bounded!(i32 => u8, u16);
396#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i32> for u128 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: i32) -> Result<Self, Self::Error> {
if u >= 0 { Ok(u as Self) } else { Err(TryFromIntError(())) }
}
}impl_try_from_lower_bounded!(i32 => u32, u64, u128);
397#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i64> for u32 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: i64) -> Result<Self, Self::Error> {
let min = Self::MIN as i64;
let max = Self::MAX as i64;
if u < min || u > max {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_both_bounded!(i64 => u8, u16, u32);
398#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i64> for u128 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: i64) -> Result<Self, Self::Error> {
if u >= 0 { Ok(u as Self) } else { Err(TryFromIntError(())) }
}
}impl_try_from_lower_bounded!(i64 => u64, u128);
399#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i128> for u64 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: i128) -> Result<Self, Self::Error> {
let min = Self::MIN as i128;
let max = Self::MAX as i128;
if u < min || u > max {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_both_bounded!(i128 => u8, u16, u32, u64);
400#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i128> for u128 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: i128) -> Result<Self, Self::Error> {
if u >= 0 { Ok(u as Self) } else { Err(TryFromIntError(())) }
}
}impl_try_from_lower_bounded!(i128 => u128);
401
402#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<usize> for isize {
type Error = TryFromIntError;
#[inline]
fn try_from(u: usize) -> Result<Self, Self::Error> {
if u > (Self::MAX as usize) {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(usize => isize);
404#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<isize> for usize {
type Error = TryFromIntError;
#[inline]
fn try_from(u: isize) -> Result<Self, Self::Error> {
if u >= 0 { Ok(u as Self) } else { Err(TryFromIntError(())) }
}
}impl_try_from_lower_bounded!(isize => usize);
405
406#[cfg(target_pointer_width = "16")]
407mod ptr_try_from_impls {
408 use super::TryFromIntError;
409
410 impl_try_from_upper_bounded!(usize => u8);
411 impl_try_from_unbounded!(usize => u16, u32, u64, u128);
412 impl_try_from_upper_bounded!(usize => i8, i16);
413 impl_try_from_unbounded!(usize => i32, i64, i128);
414
415 impl_try_from_both_bounded!(isize => u8);
416 impl_try_from_lower_bounded!(isize => u16, u32, u64, u128);
417 impl_try_from_both_bounded!(isize => i8);
418 impl_try_from_unbounded!(isize => i16, i32, i64, i128);
419
420 rev!(impl_try_from_upper_bounded, usize => u32, u64, u128);
421 rev!(impl_try_from_lower_bounded, usize => i8, i16);
422 rev!(impl_try_from_both_bounded, usize => i32, i64, i128);
423
424 rev!(impl_try_from_upper_bounded, isize => u16, u32, u64, u128);
425 rev!(impl_try_from_both_bounded, isize => i32, i64, i128);
426}
427
428#[cfg(target_pointer_width = "32")]
429mod ptr_try_from_impls {
430 use super::TryFromIntError;
431
432 impl_try_from_upper_bounded!(usize => u8, u16);
433 impl_try_from_unbounded!(usize => u32, u64, u128);
434 impl_try_from_upper_bounded!(usize => i8, i16, i32);
435 impl_try_from_unbounded!(usize => i64, i128);
436
437 impl_try_from_both_bounded!(isize => u8, u16);
438 impl_try_from_lower_bounded!(isize => u32, u64, u128);
439 impl_try_from_both_bounded!(isize => i8, i16);
440 impl_try_from_unbounded!(isize => i32, i64, i128);
441
442 rev!(impl_try_from_unbounded, usize => u32);
443 rev!(impl_try_from_upper_bounded, usize => u64, u128);
444 rev!(impl_try_from_lower_bounded, usize => i8, i16, i32);
445 rev!(impl_try_from_both_bounded, usize => i64, i128);
446
447 rev!(impl_try_from_unbounded, isize => u16);
448 rev!(impl_try_from_upper_bounded, isize => u32, u64, u128);
449 rev!(impl_try_from_unbounded, isize => i32);
450 rev!(impl_try_from_both_bounded, isize => i64, i128);
451}
452
453#[cfg(target_pointer_width = "64")]
454mod ptr_try_from_impls {
455 use super::TryFromIntError;
456
457 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<usize> for u32 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: usize) -> Result<Self, Self::Error> {
if u > (Self::MAX as usize) {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(usize => u8, u16, u32);
458 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<usize> for u128 {
type Error = TryFromIntError;
#[inline]
fn try_from(value: usize) -> Result<Self, Self::Error> {
Ok(value as Self)
}
}impl_try_from_unbounded!(usize => u64, u128);
459 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<usize> for i64 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: usize) -> Result<Self, Self::Error> {
if u > (Self::MAX as usize) {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(usize => i8, i16, i32, i64);
460 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<usize> for i128 {
type Error = TryFromIntError;
#[inline]
fn try_from(value: usize) -> Result<Self, Self::Error> {
Ok(value as Self)
}
}impl_try_from_unbounded!(usize => i128);
461
462 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<isize> for u32 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: isize) -> Result<Self, Self::Error> {
let min = Self::MIN as isize;
let max = Self::MAX as isize;
if u < min || u > max {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_both_bounded!(isize => u8, u16, u32);
463 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<isize> for u128 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: isize) -> Result<Self, Self::Error> {
if u >= 0 { Ok(u as Self) } else { Err(TryFromIntError(())) }
}
}impl_try_from_lower_bounded!(isize => u64, u128);
464 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<isize> for i32 {
type Error = TryFromIntError;
#[inline]
fn try_from(u: isize) -> Result<Self, Self::Error> {
let min = Self::MIN as isize;
let max = Self::MAX as isize;
if u < min || u > max {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}impl_try_from_both_bounded!(isize => i8, i16, i32);
465 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<isize> for i128 {
type Error = TryFromIntError;
#[inline]
fn try_from(value: isize) -> Result<Self, Self::Error> {
Ok(value as Self)
}
}impl_try_from_unbounded!(isize => i64, i128);
466
467 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u64> for usize {
type Error = TryFromIntError;
#[inline]
fn try_from(value: u64) -> Result<Self, Self::Error> { Ok(value as Self) }
}rev!(impl_try_from_unbounded, usize => u32, u64);
468 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u128> for usize {
type Error = TryFromIntError;
#[inline]
fn try_from(u: u128) -> Result<Self, Self::Error> {
if u > (Self::MAX as u128) {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}rev!(impl_try_from_upper_bounded, usize => u128);
469 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i64> for usize {
type Error = TryFromIntError;
#[inline]
fn try_from(u: i64) -> Result<Self, Self::Error> {
if u >= 0 { Ok(u as Self) } else { Err(TryFromIntError(())) }
}
}rev!(impl_try_from_lower_bounded, usize => i8, i16, i32, i64);
470 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i128> for usize {
type Error = TryFromIntError;
#[inline]
fn try_from(u: i128) -> Result<Self, Self::Error> {
let min = Self::MIN as i128;
let max = Self::MAX as i128;
if u < min || u > max {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}rev!(impl_try_from_both_bounded, usize => i128);
471
472 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u32> for isize {
type Error = TryFromIntError;
#[inline]
fn try_from(value: u32) -> Result<Self, Self::Error> { Ok(value as Self) }
}rev!(impl_try_from_unbounded, isize => u16, u32);
473 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u128> for isize {
type Error = TryFromIntError;
#[inline]
fn try_from(u: u128) -> Result<Self, Self::Error> {
if u > (Self::MAX as u128) {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}rev!(impl_try_from_upper_bounded, isize => u64, u128);
474 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i64> for isize {
type Error = TryFromIntError;
#[inline]
fn try_from(value: i64) -> Result<Self, Self::Error> { Ok(value as Self) }
}rev!(impl_try_from_unbounded, isize => i32, i64);
475 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i128> for isize {
type Error = TryFromIntError;
#[inline]
fn try_from(u: i128) -> Result<Self, Self::Error> {
let min = Self::MIN as i128;
let max = Self::MAX as i128;
if u < min || u > max {
Err(TryFromIntError(()))
} else { Ok(u as Self) }
}
}rev!(impl_try_from_both_bounded, isize => i128);
476}
477
478use crate::num::NonZero;
480
481macro_rules! impl_nonzero_int_from_nonzero_int {
482 ($Small:ty => $Large:ty) => {
483 #[stable(feature = "nz_int_conv", since = "1.41.0")]
484 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
485 impl const From<NonZero<$Small>> for NonZero<$Large> {
486 #[doc = concat!("Converts <code>[NonZero]\\<[", stringify!($Small), "]></code> ")]
489 #[doc = concat!("to <code>[NonZero]\\<[", stringify!($Large), "]></code> losslessly.")]
490 #[inline]
491 fn from(small: NonZero<$Small>) -> Self {
492 unsafe { Self::new_unchecked(From::from(small.get())) }
494 }
495 }
496 };
497}
498
499#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u8>> for NonZero<u16> {
#[doc = "Converts <code>[NonZero]\\<[u8]></code> "]
#[doc = "to <code>[NonZero]\\<[u16]></code> losslessly."]
#[inline]
fn from(small: NonZero<u8>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u8 => u16);
501#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u8>> for NonZero<u32> {
#[doc = "Converts <code>[NonZero]\\<[u8]></code> "]
#[doc = "to <code>[NonZero]\\<[u32]></code> losslessly."]
#[inline]
fn from(small: NonZero<u8>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u8 => u32);
502#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u8>> for NonZero<u64> {
#[doc = "Converts <code>[NonZero]\\<[u8]></code> "]
#[doc = "to <code>[NonZero]\\<[u64]></code> losslessly."]
#[inline]
fn from(small: NonZero<u8>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u8 => u64);
503#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u8>> for NonZero<u128> {
#[doc = "Converts <code>[NonZero]\\<[u8]></code> "]
#[doc = "to <code>[NonZero]\\<[u128]></code> losslessly."]
#[inline]
fn from(small: NonZero<u8>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u8 => u128);
504#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u8>> for NonZero<usize> {
#[doc = "Converts <code>[NonZero]\\<[u8]></code> "]
#[doc = "to <code>[NonZero]\\<[usize]></code> losslessly."]
#[inline]
fn from(small: NonZero<u8>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u8 => usize);
505#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u16>> for NonZero<u32> {
#[doc = "Converts <code>[NonZero]\\<[u16]></code> "]
#[doc = "to <code>[NonZero]\\<[u32]></code> losslessly."]
#[inline]
fn from(small: NonZero<u16>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u16 => u32);
506#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u16>> for NonZero<u64> {
#[doc = "Converts <code>[NonZero]\\<[u16]></code> "]
#[doc = "to <code>[NonZero]\\<[u64]></code> losslessly."]
#[inline]
fn from(small: NonZero<u16>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u16 => u64);
507#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u16>> for NonZero<u128> {
#[doc = "Converts <code>[NonZero]\\<[u16]></code> "]
#[doc = "to <code>[NonZero]\\<[u128]></code> losslessly."]
#[inline]
fn from(small: NonZero<u16>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u16 => u128);
508#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u16>> for NonZero<usize> {
#[doc = "Converts <code>[NonZero]\\<[u16]></code> "]
#[doc = "to <code>[NonZero]\\<[usize]></code> losslessly."]
#[inline]
fn from(small: NonZero<u16>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u16 => usize);
509#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u32>> for NonZero<u64> {
#[doc = "Converts <code>[NonZero]\\<[u32]></code> "]
#[doc = "to <code>[NonZero]\\<[u64]></code> losslessly."]
#[inline]
fn from(small: NonZero<u32>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u32 => u64);
510#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u32>> for NonZero<u128> {
#[doc = "Converts <code>[NonZero]\\<[u32]></code> "]
#[doc = "to <code>[NonZero]\\<[u128]></code> losslessly."]
#[inline]
fn from(small: NonZero<u32>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u32 => u128);
511#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u64>> for NonZero<u128> {
#[doc = "Converts <code>[NonZero]\\<[u64]></code> "]
#[doc = "to <code>[NonZero]\\<[u128]></code> losslessly."]
#[inline]
fn from(small: NonZero<u64>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u64 => u128);
512
513#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i8>> for NonZero<i16> {
#[doc = "Converts <code>[NonZero]\\<[i8]></code> "]
#[doc = "to <code>[NonZero]\\<[i16]></code> losslessly."]
#[inline]
fn from(small: NonZero<i8>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(i8 => i16);
515#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i8>> for NonZero<i32> {
#[doc = "Converts <code>[NonZero]\\<[i8]></code> "]
#[doc = "to <code>[NonZero]\\<[i32]></code> losslessly."]
#[inline]
fn from(small: NonZero<i8>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(i8 => i32);
516#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i8>> for NonZero<i64> {
#[doc = "Converts <code>[NonZero]\\<[i8]></code> "]
#[doc = "to <code>[NonZero]\\<[i64]></code> losslessly."]
#[inline]
fn from(small: NonZero<i8>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(i8 => i64);
517#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i8>> for NonZero<i128> {
#[doc = "Converts <code>[NonZero]\\<[i8]></code> "]
#[doc = "to <code>[NonZero]\\<[i128]></code> losslessly."]
#[inline]
fn from(small: NonZero<i8>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(i8 => i128);
518#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i8>> for NonZero<isize> {
#[doc = "Converts <code>[NonZero]\\<[i8]></code> "]
#[doc = "to <code>[NonZero]\\<[isize]></code> losslessly."]
#[inline]
fn from(small: NonZero<i8>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(i8 => isize);
519#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i16>> for NonZero<i32> {
#[doc = "Converts <code>[NonZero]\\<[i16]></code> "]
#[doc = "to <code>[NonZero]\\<[i32]></code> losslessly."]
#[inline]
fn from(small: NonZero<i16>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(i16 => i32);
520#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i16>> for NonZero<i64> {
#[doc = "Converts <code>[NonZero]\\<[i16]></code> "]
#[doc = "to <code>[NonZero]\\<[i64]></code> losslessly."]
#[inline]
fn from(small: NonZero<i16>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(i16 => i64);
521#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i16>> for NonZero<i128> {
#[doc = "Converts <code>[NonZero]\\<[i16]></code> "]
#[doc = "to <code>[NonZero]\\<[i128]></code> losslessly."]
#[inline]
fn from(small: NonZero<i16>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(i16 => i128);
522#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i16>> for NonZero<isize> {
#[doc = "Converts <code>[NonZero]\\<[i16]></code> "]
#[doc = "to <code>[NonZero]\\<[isize]></code> losslessly."]
#[inline]
fn from(small: NonZero<i16>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(i16 => isize);
523#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i32>> for NonZero<i64> {
#[doc = "Converts <code>[NonZero]\\<[i32]></code> "]
#[doc = "to <code>[NonZero]\\<[i64]></code> losslessly."]
#[inline]
fn from(small: NonZero<i32>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(i32 => i64);
524#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i32>> for NonZero<i128> {
#[doc = "Converts <code>[NonZero]\\<[i32]></code> "]
#[doc = "to <code>[NonZero]\\<[i128]></code> losslessly."]
#[inline]
fn from(small: NonZero<i32>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(i32 => i128);
525#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i64>> for NonZero<i128> {
#[doc = "Converts <code>[NonZero]\\<[i64]></code> "]
#[doc = "to <code>[NonZero]\\<[i128]></code> losslessly."]
#[inline]
fn from(small: NonZero<i64>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(i64 => i128);
526
527#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u8>> for NonZero<i16> {
#[doc = "Converts <code>[NonZero]\\<[u8]></code> "]
#[doc = "to <code>[NonZero]\\<[i16]></code> losslessly."]
#[inline]
fn from(small: NonZero<u8>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u8 => i16);
529#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u8>> for NonZero<i32> {
#[doc = "Converts <code>[NonZero]\\<[u8]></code> "]
#[doc = "to <code>[NonZero]\\<[i32]></code> losslessly."]
#[inline]
fn from(small: NonZero<u8>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u8 => i32);
530#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u8>> for NonZero<i64> {
#[doc = "Converts <code>[NonZero]\\<[u8]></code> "]
#[doc = "to <code>[NonZero]\\<[i64]></code> losslessly."]
#[inline]
fn from(small: NonZero<u8>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u8 => i64);
531#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u8>> for NonZero<i128> {
#[doc = "Converts <code>[NonZero]\\<[u8]></code> "]
#[doc = "to <code>[NonZero]\\<[i128]></code> losslessly."]
#[inline]
fn from(small: NonZero<u8>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u8 => i128);
532#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u8>> for NonZero<isize> {
#[doc = "Converts <code>[NonZero]\\<[u8]></code> "]
#[doc = "to <code>[NonZero]\\<[isize]></code> losslessly."]
#[inline]
fn from(small: NonZero<u8>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u8 => isize);
533#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u16>> for NonZero<i32> {
#[doc = "Converts <code>[NonZero]\\<[u16]></code> "]
#[doc = "to <code>[NonZero]\\<[i32]></code> losslessly."]
#[inline]
fn from(small: NonZero<u16>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u16 => i32);
534#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u16>> for NonZero<i64> {
#[doc = "Converts <code>[NonZero]\\<[u16]></code> "]
#[doc = "to <code>[NonZero]\\<[i64]></code> losslessly."]
#[inline]
fn from(small: NonZero<u16>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u16 => i64);
535#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u16>> for NonZero<i128> {
#[doc = "Converts <code>[NonZero]\\<[u16]></code> "]
#[doc = "to <code>[NonZero]\\<[i128]></code> losslessly."]
#[inline]
fn from(small: NonZero<u16>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u16 => i128);
536#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u32>> for NonZero<i64> {
#[doc = "Converts <code>[NonZero]\\<[u32]></code> "]
#[doc = "to <code>[NonZero]\\<[i64]></code> losslessly."]
#[inline]
fn from(small: NonZero<u32>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u32 => i64);
537#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u32>> for NonZero<i128> {
#[doc = "Converts <code>[NonZero]\\<[u32]></code> "]
#[doc = "to <code>[NonZero]\\<[i128]></code> losslessly."]
#[inline]
fn from(small: NonZero<u32>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u32 => i128);
538#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u64>> for NonZero<i128> {
#[doc = "Converts <code>[NonZero]\\<[u64]></code> "]
#[doc = "to <code>[NonZero]\\<[i128]></code> losslessly."]
#[inline]
fn from(small: NonZero<u64>) -> Self {
unsafe { Self::new_unchecked(From::from(small.get())) }
}
}impl_nonzero_int_from_nonzero_int!(u64 => i128);
539
540macro_rules! impl_nonzero_int_try_from_int {
541 ($Int:ty) => {
542 #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
543 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
544 impl const TryFrom<$Int> for NonZero<$Int> {
545 type Error = TryFromIntError;
546
547 #[doc = concat!("Attempts to convert [`", stringify!($Int), "`] ")]
550 #[doc = concat!("to <code>[NonZero]\\<[", stringify!($Int), "]></code>.")]
551 #[inline]
552 fn try_from(value: $Int) -> Result<Self, Self::Error> {
553 Self::new(value).ok_or(TryFromIntError(()))
554 }
555 }
556 };
557}
558
559#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u8> for NonZero<u8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert [`u8`] "]
#[doc = "to <code>[NonZero]\\<[u8]></code>."]
#[inline]
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::new(value).ok_or(TryFromIntError(()))
}
}impl_nonzero_int_try_from_int!(u8);
561#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u16> for NonZero<u16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert [`u16`] "]
#[doc = "to <code>[NonZero]\\<[u16]></code>."]
#[inline]
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::new(value).ok_or(TryFromIntError(()))
}
}impl_nonzero_int_try_from_int!(u16);
562#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u32> for NonZero<u32> {
type Error = TryFromIntError;
#[doc = "Attempts to convert [`u32`] "]
#[doc = "to <code>[NonZero]\\<[u32]></code>."]
#[inline]
fn try_from(value: u32) -> Result<Self, Self::Error> {
Self::new(value).ok_or(TryFromIntError(()))
}
}impl_nonzero_int_try_from_int!(u32);
563#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u64> for NonZero<u64> {
type Error = TryFromIntError;
#[doc = "Attempts to convert [`u64`] "]
#[doc = "to <code>[NonZero]\\<[u64]></code>."]
#[inline]
fn try_from(value: u64) -> Result<Self, Self::Error> {
Self::new(value).ok_or(TryFromIntError(()))
}
}impl_nonzero_int_try_from_int!(u64);
564#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u128> for NonZero<u128> {
type Error = TryFromIntError;
#[doc = "Attempts to convert [`u128`] "]
#[doc = "to <code>[NonZero]\\<[u128]></code>."]
#[inline]
fn try_from(value: u128) -> Result<Self, Self::Error> {
Self::new(value).ok_or(TryFromIntError(()))
}
}impl_nonzero_int_try_from_int!(u128);
565#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<usize> for NonZero<usize> {
type Error = TryFromIntError;
#[doc = "Attempts to convert [`usize`] "]
#[doc = "to <code>[NonZero]\\<[usize]></code>."]
#[inline]
fn try_from(value: usize) -> Result<Self, Self::Error> {
Self::new(value).ok_or(TryFromIntError(()))
}
}impl_nonzero_int_try_from_int!(usize);
566#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i8> for NonZero<i8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert [`i8`] "]
#[doc = "to <code>[NonZero]\\<[i8]></code>."]
#[inline]
fn try_from(value: i8) -> Result<Self, Self::Error> {
Self::new(value).ok_or(TryFromIntError(()))
}
}impl_nonzero_int_try_from_int!(i8);
567#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i16> for NonZero<i16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert [`i16`] "]
#[doc = "to <code>[NonZero]\\<[i16]></code>."]
#[inline]
fn try_from(value: i16) -> Result<Self, Self::Error> {
Self::new(value).ok_or(TryFromIntError(()))
}
}impl_nonzero_int_try_from_int!(i16);
568#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i32> for NonZero<i32> {
type Error = TryFromIntError;
#[doc = "Attempts to convert [`i32`] "]
#[doc = "to <code>[NonZero]\\<[i32]></code>."]
#[inline]
fn try_from(value: i32) -> Result<Self, Self::Error> {
Self::new(value).ok_or(TryFromIntError(()))
}
}impl_nonzero_int_try_from_int!(i32);
569#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i64> for NonZero<i64> {
type Error = TryFromIntError;
#[doc = "Attempts to convert [`i64`] "]
#[doc = "to <code>[NonZero]\\<[i64]></code>."]
#[inline]
fn try_from(value: i64) -> Result<Self, Self::Error> {
Self::new(value).ok_or(TryFromIntError(()))
}
}impl_nonzero_int_try_from_int!(i64);
570#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i128> for NonZero<i128> {
type Error = TryFromIntError;
#[doc = "Attempts to convert [`i128`] "]
#[doc = "to <code>[NonZero]\\<[i128]></code>."]
#[inline]
fn try_from(value: i128) -> Result<Self, Self::Error> {
Self::new(value).ok_or(TryFromIntError(()))
}
}impl_nonzero_int_try_from_int!(i128);
571#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<isize> for NonZero<isize> {
type Error = TryFromIntError;
#[doc = "Attempts to convert [`isize`] "]
#[doc = "to <code>[NonZero]\\<[isize]></code>."]
#[inline]
fn try_from(value: isize) -> Result<Self, Self::Error> {
Self::new(value).ok_or(TryFromIntError(()))
}
}impl_nonzero_int_try_from_int!(isize);
572
573macro_rules! impl_nonzero_int_try_from_nonzero_int {
574 ($source:ty => $($target:ty),+) => {$(
575 #[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
576 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
577 impl const TryFrom<NonZero<$source>> for NonZero<$target> {
578 type Error = TryFromIntError;
579
580 #[doc = concat!("Attempts to convert <code>[NonZero]\\<[", stringify!($source), "]></code> ")]
583 #[doc = concat!("to <code>[NonZero]\\<[", stringify!($target), "]></code>.")]
584 #[inline]
585 fn try_from(value: NonZero<$source>) -> Result<Self, Self::Error> {
586 Ok(unsafe { Self::new_unchecked(<$target>::try_from(value.get())?) })
588 }
589 }
590 )*};
591}
592
593#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<u16>> for NonZero<u8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u16]></code> "]
#[doc = "to <code>[NonZero]\\<[u8]></code>."]
#[inline]
fn try_from(value: NonZero<u16>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u8>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(u16 => u8);
595#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<u32>> for NonZero<usize> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u32]></code> "]
#[doc = "to <code>[NonZero]\\<[usize]></code>."]
#[inline]
fn try_from(value: NonZero<u32>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<usize>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(u32 => u8, u16, usize);
596#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<u64>> for NonZero<usize> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u64]></code> "]
#[doc = "to <code>[NonZero]\\<[usize]></code>."]
#[inline]
fn try_from(value: NonZero<u64>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<usize>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(u64 => u8, u16, u32, usize);
597#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<u128>> for NonZero<usize> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u128]></code> "]
#[doc = "to <code>[NonZero]\\<[usize]></code>."]
#[inline]
fn try_from(value: NonZero<u128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<usize>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(u128 => u8, u16, u32, u64, usize);
598#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<usize>> for NonZero<u128> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[usize]></code> "]
#[doc = "to <code>[NonZero]\\<[u128]></code>."]
#[inline]
fn try_from(value: NonZero<usize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u128>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(usize => u8, u16, u32, u64, u128);
599
600#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<i16>> for NonZero<i8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i16]></code> "]
#[doc = "to <code>[NonZero]\\<[i8]></code>."]
#[inline]
fn try_from(value: NonZero<i16>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i8>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(i16 => i8);
602#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<i32>> for NonZero<isize> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i32]></code> "]
#[doc = "to <code>[NonZero]\\<[isize]></code>."]
#[inline]
fn try_from(value: NonZero<i32>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<isize>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(i32 => i8, i16, isize);
603#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<i64>> for NonZero<isize> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i64]></code> "]
#[doc = "to <code>[NonZero]\\<[isize]></code>."]
#[inline]
fn try_from(value: NonZero<i64>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<isize>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(i64 => i8, i16, i32, isize);
604#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<i128>> for NonZero<isize> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i128]></code> "]
#[doc = "to <code>[NonZero]\\<[isize]></code>."]
#[inline]
fn try_from(value: NonZero<i128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<isize>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(i128 => i8, i16, i32, i64, isize);
605#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<isize>> for NonZero<i128> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[isize]></code> "]
#[doc = "to <code>[NonZero]\\<[i128]></code>."]
#[inline]
fn try_from(value: NonZero<isize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i128>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(isize => i8, i16, i32, i64, i128);
606
607#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<u8>> for NonZero<i8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u8]></code> "]
#[doc = "to <code>[NonZero]\\<[i8]></code>."]
#[inline]
fn try_from(value: NonZero<u8>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i8>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(u8 => i8);
609#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<u16>> for NonZero<isize> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u16]></code> "]
#[doc = "to <code>[NonZero]\\<[isize]></code>."]
#[inline]
fn try_from(value: NonZero<u16>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<isize>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(u16 => i8, i16, isize);
610#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<u32>> for NonZero<isize> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u32]></code> "]
#[doc = "to <code>[NonZero]\\<[isize]></code>."]
#[inline]
fn try_from(value: NonZero<u32>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<isize>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(u32 => i8, i16, i32, isize);
611#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<u64>> for NonZero<isize> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u64]></code> "]
#[doc = "to <code>[NonZero]\\<[isize]></code>."]
#[inline]
fn try_from(value: NonZero<u64>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<isize>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(u64 => i8, i16, i32, i64, isize);
612#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<u128>> for NonZero<isize> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u128]></code> "]
#[doc = "to <code>[NonZero]\\<[isize]></code>."]
#[inline]
fn try_from(value: NonZero<u128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<isize>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(u128 => i8, i16, i32, i64, i128, isize);
613#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<usize>> for NonZero<isize> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[usize]></code> "]
#[doc = "to <code>[NonZero]\\<[isize]></code>."]
#[inline]
fn try_from(value: NonZero<usize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<isize>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(usize => i8, i16, i32, i64, i128, isize);
614
615#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<i8>> for NonZero<usize> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i8]></code> "]
#[doc = "to <code>[NonZero]\\<[usize]></code>."]
#[inline]
fn try_from(value: NonZero<i8>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<usize>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(i8 => u8, u16, u32, u64, u128, usize);
617#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<i16>> for NonZero<usize> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i16]></code> "]
#[doc = "to <code>[NonZero]\\<[usize]></code>."]
#[inline]
fn try_from(value: NonZero<i16>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<usize>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(i16 => u8, u16, u32, u64, u128, usize);
618#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<i32>> for NonZero<usize> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i32]></code> "]
#[doc = "to <code>[NonZero]\\<[usize]></code>."]
#[inline]
fn try_from(value: NonZero<i32>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<usize>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(i32 => u8, u16, u32, u64, u128, usize);
619#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<i64>> for NonZero<usize> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i64]></code> "]
#[doc = "to <code>[NonZero]\\<[usize]></code>."]
#[inline]
fn try_from(value: NonZero<i64>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<usize>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(i64 => u8, u16, u32, u64, u128, usize);
620#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<i128>> for NonZero<usize> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i128]></code> "]
#[doc = "to <code>[NonZero]\\<[usize]></code>."]
#[inline]
fn try_from(value: NonZero<i128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<usize>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(i128 => u8, u16, u32, u64, u128, usize);
621#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<isize>> for NonZero<usize> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[isize]></code> "]
#[doc = "to <code>[NonZero]\\<[usize]></code>."]
#[inline]
fn try_from(value: NonZero<isize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<usize>::try_from(value.get())?) })
}
}impl_nonzero_int_try_from_nonzero_int!(isize => u8, u16, u32, u64, u128, usize);