1use crate::num::{IntErrorKind, TryFromIntError};
2
3#[unstable(feature = "convert_float_to_int", issue = "67057")]
6pub impl(self) trait FloatToInt<Int>: Sized {
7 #[unstable(feature = "convert_float_to_int", issue = "67057")]
8 #[doc(hidden)]
9 unsafe fn to_int_unchecked(self) -> Int;
10
11 #[unstable(feature = "float_conversions", issue = "159913")]
12 #[doc(hidden)]
13 fn to_int_saturating(self) -> Int;
14
15 #[unstable(feature = "float_conversions", issue = "159913")]
16 #[doc(hidden)]
17 fn to_int_checked(self) -> Option<Int>;
18}
19
20macro_rules! impl_float_to_int {
21 ($Float:ty => $($Int:ty),+) => {
22 $(
23 #[unstable(feature = "convert_float_to_int", issue = "67057")]
24 impl FloatToInt<$Int> for $Float {
25 #[inline]
26 unsafe fn to_int_unchecked(self) -> $Int {
27 unsafe { crate::intrinsics::float_to_int_unchecked(self) }
29 }
30 #[inline]
31 fn to_int_saturating(self) -> $Int {
32 self as $Int
34 }
35 #[inline]
36 fn to_int_checked(self) -> Option<$Int> {
37 const LOW_THRESHOLD: $Float = {
44 let int_min = <$Int>::MIN as $Float;
47 let one_below_if_representable = int_min - 1.0;
48 if one_below_if_representable == int_min {
49 int_min.next_down()
52 } else {
53 one_below_if_representable
54 }
55 };
56
57 const HIGH_THRESHOLD: $Float = {
58 let half = (<$Int>::MAX / 2) + 1;
64 half as $Float + half as $Float
65 };
66
67 if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
70 Some(unsafe { self.to_int_unchecked() })
72 } else {
73 None
74 }
75 }
76 }
77 )+
78 }
79}
80
81#[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) }
}
#[inline]
fn to_int_saturating(self) -> u8 { self as u8 }
#[inline]
fn to_int_checked(self) -> Option<u8> {
const LOW_THRESHOLD: f16 =
{
let int_min = <u8>::MIN as f16;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f16 =
{ let half = (<u8>::MAX / 2) + 1; half as f16 + half as f16 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> u16 { self as u16 }
#[inline]
fn to_int_checked(self) -> Option<u16> {
const LOW_THRESHOLD: f16 =
{
let int_min = <u16>::MIN as f16;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f16 =
{ let half = (<u16>::MAX / 2) + 1; half as f16 + half as f16 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> u32 { self as u32 }
#[inline]
fn to_int_checked(self) -> Option<u32> {
const LOW_THRESHOLD: f16 =
{
let int_min = <u32>::MIN as f16;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f16 =
{ let half = (<u32>::MAX / 2) + 1; half as f16 + half as f16 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> u64 { self as u64 }
#[inline]
fn to_int_checked(self) -> Option<u64> {
const LOW_THRESHOLD: f16 =
{
let int_min = <u64>::MIN as f16;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f16 =
{ let half = (<u64>::MAX / 2) + 1; half as f16 + half as f16 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> u128 { self as u128 }
#[inline]
fn to_int_checked(self) -> Option<u128> {
const LOW_THRESHOLD: f16 =
{
let int_min = <u128>::MIN as f16;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f16 =
{ let half = (<u128>::MAX / 2) + 1; half as f16 + half as f16 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> usize { self as usize }
#[inline]
fn to_int_checked(self) -> Option<usize> {
const LOW_THRESHOLD: f16 =
{
let int_min = <usize>::MIN as f16;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f16 =
{ let half = (<usize>::MAX / 2) + 1; half as f16 + half as f16 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> i8 { self as i8 }
#[inline]
fn to_int_checked(self) -> Option<i8> {
const LOW_THRESHOLD: f16 =
{
let int_min = <i8>::MIN as f16;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f16 =
{ let half = (<i8>::MAX / 2) + 1; half as f16 + half as f16 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> i16 { self as i16 }
#[inline]
fn to_int_checked(self) -> Option<i16> {
const LOW_THRESHOLD: f16 =
{
let int_min = <i16>::MIN as f16;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f16 =
{ let half = (<i16>::MAX / 2) + 1; half as f16 + half as f16 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> i32 { self as i32 }
#[inline]
fn to_int_checked(self) -> Option<i32> {
const LOW_THRESHOLD: f16 =
{
let int_min = <i32>::MIN as f16;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f16 =
{ let half = (<i32>::MAX / 2) + 1; half as f16 + half as f16 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> i64 { self as i64 }
#[inline]
fn to_int_checked(self) -> Option<i64> {
const LOW_THRESHOLD: f16 =
{
let int_min = <i64>::MIN as f16;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f16 =
{ let half = (<i64>::MAX / 2) + 1; half as f16 + half as f16 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> i128 { self as i128 }
#[inline]
fn to_int_checked(self) -> Option<i128> {
const LOW_THRESHOLD: f16 =
{
let int_min = <i128>::MIN as f16;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f16 =
{ let half = (<i128>::MAX / 2) + 1; half as f16 + half as f16 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> isize { self as isize }
#[inline]
fn to_int_checked(self) -> Option<isize> {
const LOW_THRESHOLD: f16 =
{
let int_min = <isize>::MIN as f16;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f16 =
{ let half = (<isize>::MAX / 2) + 1; half as f16 + half as f16 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}impl_float_to_int!(f16 => u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
82#[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) }
}
#[inline]
fn to_int_saturating(self) -> u8 { self as u8 }
#[inline]
fn to_int_checked(self) -> Option<u8> {
const LOW_THRESHOLD: f32 =
{
let int_min = <u8>::MIN as f32;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f32 =
{ let half = (<u8>::MAX / 2) + 1; half as f32 + half as f32 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> u16 { self as u16 }
#[inline]
fn to_int_checked(self) -> Option<u16> {
const LOW_THRESHOLD: f32 =
{
let int_min = <u16>::MIN as f32;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f32 =
{ let half = (<u16>::MAX / 2) + 1; half as f32 + half as f32 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> u32 { self as u32 }
#[inline]
fn to_int_checked(self) -> Option<u32> {
const LOW_THRESHOLD: f32 =
{
let int_min = <u32>::MIN as f32;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f32 =
{ let half = (<u32>::MAX / 2) + 1; half as f32 + half as f32 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> u64 { self as u64 }
#[inline]
fn to_int_checked(self) -> Option<u64> {
const LOW_THRESHOLD: f32 =
{
let int_min = <u64>::MIN as f32;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f32 =
{ let half = (<u64>::MAX / 2) + 1; half as f32 + half as f32 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> u128 { self as u128 }
#[inline]
fn to_int_checked(self) -> Option<u128> {
const LOW_THRESHOLD: f32 =
{
let int_min = <u128>::MIN as f32;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f32 =
{ let half = (<u128>::MAX / 2) + 1; half as f32 + half as f32 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> usize { self as usize }
#[inline]
fn to_int_checked(self) -> Option<usize> {
const LOW_THRESHOLD: f32 =
{
let int_min = <usize>::MIN as f32;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f32 =
{ let half = (<usize>::MAX / 2) + 1; half as f32 + half as f32 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> i8 { self as i8 }
#[inline]
fn to_int_checked(self) -> Option<i8> {
const LOW_THRESHOLD: f32 =
{
let int_min = <i8>::MIN as f32;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f32 =
{ let half = (<i8>::MAX / 2) + 1; half as f32 + half as f32 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> i16 { self as i16 }
#[inline]
fn to_int_checked(self) -> Option<i16> {
const LOW_THRESHOLD: f32 =
{
let int_min = <i16>::MIN as f32;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f32 =
{ let half = (<i16>::MAX / 2) + 1; half as f32 + half as f32 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> i32 { self as i32 }
#[inline]
fn to_int_checked(self) -> Option<i32> {
const LOW_THRESHOLD: f32 =
{
let int_min = <i32>::MIN as f32;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f32 =
{ let half = (<i32>::MAX / 2) + 1; half as f32 + half as f32 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> i64 { self as i64 }
#[inline]
fn to_int_checked(self) -> Option<i64> {
const LOW_THRESHOLD: f32 =
{
let int_min = <i64>::MIN as f32;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f32 =
{ let half = (<i64>::MAX / 2) + 1; half as f32 + half as f32 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> i128 { self as i128 }
#[inline]
fn to_int_checked(self) -> Option<i128> {
const LOW_THRESHOLD: f32 =
{
let int_min = <i128>::MIN as f32;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f32 =
{ let half = (<i128>::MAX / 2) + 1; half as f32 + half as f32 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> isize { self as isize }
#[inline]
fn to_int_checked(self) -> Option<isize> {
const LOW_THRESHOLD: f32 =
{
let int_min = <isize>::MIN as f32;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f32 =
{ let half = (<isize>::MAX / 2) + 1; half as f32 + half as f32 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}impl_float_to_int!(f32 => u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
83#[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) }
}
#[inline]
fn to_int_saturating(self) -> u8 { self as u8 }
#[inline]
fn to_int_checked(self) -> Option<u8> {
const LOW_THRESHOLD: f64 =
{
let int_min = <u8>::MIN as f64;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f64 =
{ let half = (<u8>::MAX / 2) + 1; half as f64 + half as f64 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> u16 { self as u16 }
#[inline]
fn to_int_checked(self) -> Option<u16> {
const LOW_THRESHOLD: f64 =
{
let int_min = <u16>::MIN as f64;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f64 =
{ let half = (<u16>::MAX / 2) + 1; half as f64 + half as f64 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> u32 { self as u32 }
#[inline]
fn to_int_checked(self) -> Option<u32> {
const LOW_THRESHOLD: f64 =
{
let int_min = <u32>::MIN as f64;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f64 =
{ let half = (<u32>::MAX / 2) + 1; half as f64 + half as f64 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> u64 { self as u64 }
#[inline]
fn to_int_checked(self) -> Option<u64> {
const LOW_THRESHOLD: f64 =
{
let int_min = <u64>::MIN as f64;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f64 =
{ let half = (<u64>::MAX / 2) + 1; half as f64 + half as f64 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> u128 { self as u128 }
#[inline]
fn to_int_checked(self) -> Option<u128> {
const LOW_THRESHOLD: f64 =
{
let int_min = <u128>::MIN as f64;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f64 =
{ let half = (<u128>::MAX / 2) + 1; half as f64 + half as f64 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> usize { self as usize }
#[inline]
fn to_int_checked(self) -> Option<usize> {
const LOW_THRESHOLD: f64 =
{
let int_min = <usize>::MIN as f64;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f64 =
{ let half = (<usize>::MAX / 2) + 1; half as f64 + half as f64 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> i8 { self as i8 }
#[inline]
fn to_int_checked(self) -> Option<i8> {
const LOW_THRESHOLD: f64 =
{
let int_min = <i8>::MIN as f64;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f64 =
{ let half = (<i8>::MAX / 2) + 1; half as f64 + half as f64 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> i16 { self as i16 }
#[inline]
fn to_int_checked(self) -> Option<i16> {
const LOW_THRESHOLD: f64 =
{
let int_min = <i16>::MIN as f64;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f64 =
{ let half = (<i16>::MAX / 2) + 1; half as f64 + half as f64 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> i32 { self as i32 }
#[inline]
fn to_int_checked(self) -> Option<i32> {
const LOW_THRESHOLD: f64 =
{
let int_min = <i32>::MIN as f64;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f64 =
{ let half = (<i32>::MAX / 2) + 1; half as f64 + half as f64 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> i64 { self as i64 }
#[inline]
fn to_int_checked(self) -> Option<i64> {
const LOW_THRESHOLD: f64 =
{
let int_min = <i64>::MIN as f64;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f64 =
{ let half = (<i64>::MAX / 2) + 1; half as f64 + half as f64 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> i128 { self as i128 }
#[inline]
fn to_int_checked(self) -> Option<i128> {
const LOW_THRESHOLD: f64 =
{
let int_min = <i128>::MIN as f64;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f64 =
{ let half = (<i128>::MAX / 2) + 1; half as f64 + half as f64 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> isize { self as isize }
#[inline]
fn to_int_checked(self) -> Option<isize> {
const LOW_THRESHOLD: f64 =
{
let int_min = <isize>::MIN as f64;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f64 =
{ let half = (<isize>::MAX / 2) + 1; half as f64 + half as f64 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}impl_float_to_int!(f64 => u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
84#[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) }
}
#[inline]
fn to_int_saturating(self) -> u8 { self as u8 }
#[inline]
fn to_int_checked(self) -> Option<u8> {
const LOW_THRESHOLD: f128 =
{
let int_min = <u8>::MIN as f128;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f128 =
{ let half = (<u8>::MAX / 2) + 1; half as f128 + half as f128 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> u16 { self as u16 }
#[inline]
fn to_int_checked(self) -> Option<u16> {
const LOW_THRESHOLD: f128 =
{
let int_min = <u16>::MIN as f128;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f128 =
{ let half = (<u16>::MAX / 2) + 1; half as f128 + half as f128 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> u32 { self as u32 }
#[inline]
fn to_int_checked(self) -> Option<u32> {
const LOW_THRESHOLD: f128 =
{
let int_min = <u32>::MIN as f128;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f128 =
{ let half = (<u32>::MAX / 2) + 1; half as f128 + half as f128 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> u64 { self as u64 }
#[inline]
fn to_int_checked(self) -> Option<u64> {
const LOW_THRESHOLD: f128 =
{
let int_min = <u64>::MIN as f128;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f128 =
{ let half = (<u64>::MAX / 2) + 1; half as f128 + half as f128 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> u128 { self as u128 }
#[inline]
fn to_int_checked(self) -> Option<u128> {
const LOW_THRESHOLD: f128 =
{
let int_min = <u128>::MIN as f128;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f128 =
{ let half = (<u128>::MAX / 2) + 1; half as f128 + half as f128 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> usize { self as usize }
#[inline]
fn to_int_checked(self) -> Option<usize> {
const LOW_THRESHOLD: f128 =
{
let int_min = <usize>::MIN as f128;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f128 =
{
let half = (<usize>::MAX / 2) + 1;
half as f128 + half as f128
};
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> i8 { self as i8 }
#[inline]
fn to_int_checked(self) -> Option<i8> {
const LOW_THRESHOLD: f128 =
{
let int_min = <i8>::MIN as f128;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f128 =
{ let half = (<i8>::MAX / 2) + 1; half as f128 + half as f128 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> i16 { self as i16 }
#[inline]
fn to_int_checked(self) -> Option<i16> {
const LOW_THRESHOLD: f128 =
{
let int_min = <i16>::MIN as f128;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f128 =
{ let half = (<i16>::MAX / 2) + 1; half as f128 + half as f128 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> i32 { self as i32 }
#[inline]
fn to_int_checked(self) -> Option<i32> {
const LOW_THRESHOLD: f128 =
{
let int_min = <i32>::MIN as f128;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f128 =
{ let half = (<i32>::MAX / 2) + 1; half as f128 + half as f128 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> i64 { self as i64 }
#[inline]
fn to_int_checked(self) -> Option<i64> {
const LOW_THRESHOLD: f128 =
{
let int_min = <i64>::MIN as f128;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f128 =
{ let half = (<i64>::MAX / 2) + 1; half as f128 + half as f128 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> i128 { self as i128 }
#[inline]
fn to_int_checked(self) -> Option<i128> {
const LOW_THRESHOLD: f128 =
{
let int_min = <i128>::MIN as f128;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f128 =
{ let half = (<i128>::MAX / 2) + 1; half as f128 + half as f128 };
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}
#[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) }
}
#[inline]
fn to_int_saturating(self) -> isize { self as isize }
#[inline]
fn to_int_checked(self) -> Option<isize> {
const LOW_THRESHOLD: f128 =
{
let int_min = <isize>::MIN as f128;
let one_below_if_representable = int_min - 1.0;
if one_below_if_representable == int_min {
int_min.next_down()
} else { one_below_if_representable }
};
const HIGH_THRESHOLD: f128 =
{
let half = (<isize>::MAX / 2) + 1;
half as f128 + half as f128
};
if LOW_THRESHOLD < self && self < HIGH_THRESHOLD {
Some(unsafe { self.to_int_unchecked() })
} else { None }
}
}impl_float_to_int!(f128 => u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
85
86#[unstable(feature = "float_conversions", issue = "159913")]
89pub impl(self) trait FloatToFloat<Flt>: Sized {
90 #[unstable(feature = "float_conversions", issue = "159913")]
91 #[doc(hidden)]
92 fn cast(self) -> Flt;
93}
94
95macro_rules! impl_float_to_float {
96 ($Float:ty => $($Flt:ty),+) => {
97 $(
98 #[unstable(feature = "float_conversions", issue = "159913")]
99 impl FloatToFloat<$Flt> for $Float {
100 #[inline]
101 fn cast(self) -> $Flt {
102 self as $Flt
103 }
104 }
105 )+
106 }
107}
108
109#[unstable(feature = "float_conversions", issue = "159913")]
impl FloatToFloat<f16> for f16 {
#[inline]
fn cast(self) -> f16 { self as f16 }
}
#[unstable(feature = "float_conversions", issue = "159913")]
impl FloatToFloat<f32> for f16 {
#[inline]
fn cast(self) -> f32 { self as f32 }
}
#[unstable(feature = "float_conversions", issue = "159913")]
impl FloatToFloat<f64> for f16 {
#[inline]
fn cast(self) -> f64 { self as f64 }
}
#[unstable(feature = "float_conversions", issue = "159913")]
impl FloatToFloat<f128> for f16 {
#[inline]
fn cast(self) -> f128 { self as f128 }
}impl_float_to_float!(f16 => f16, f32, f64, f128);
110#[unstable(feature = "float_conversions", issue = "159913")]
impl FloatToFloat<f16> for f32 {
#[inline]
fn cast(self) -> f16 { self as f16 }
}
#[unstable(feature = "float_conversions", issue = "159913")]
impl FloatToFloat<f32> for f32 {
#[inline]
fn cast(self) -> f32 { self as f32 }
}
#[unstable(feature = "float_conversions", issue = "159913")]
impl FloatToFloat<f64> for f32 {
#[inline]
fn cast(self) -> f64 { self as f64 }
}
#[unstable(feature = "float_conversions", issue = "159913")]
impl FloatToFloat<f128> for f32 {
#[inline]
fn cast(self) -> f128 { self as f128 }
}impl_float_to_float!(f32 => f16, f32, f64, f128);
111#[unstable(feature = "float_conversions", issue = "159913")]
impl FloatToFloat<f16> for f64 {
#[inline]
fn cast(self) -> f16 { self as f16 }
}
#[unstable(feature = "float_conversions", issue = "159913")]
impl FloatToFloat<f32> for f64 {
#[inline]
fn cast(self) -> f32 { self as f32 }
}
#[unstable(feature = "float_conversions", issue = "159913")]
impl FloatToFloat<f64> for f64 {
#[inline]
fn cast(self) -> f64 { self as f64 }
}
#[unstable(feature = "float_conversions", issue = "159913")]
impl FloatToFloat<f128> for f64 {
#[inline]
fn cast(self) -> f128 { self as f128 }
}impl_float_to_float!(f64 => f16, f32, f64, f128);
112#[unstable(feature = "float_conversions", issue = "159913")]
impl FloatToFloat<f16> for f128 {
#[inline]
fn cast(self) -> f16 { self as f16 }
}
#[unstable(feature = "float_conversions", issue = "159913")]
impl FloatToFloat<f32> for f128 {
#[inline]
fn cast(self) -> f32 { self as f32 }
}
#[unstable(feature = "float_conversions", issue = "159913")]
impl FloatToFloat<f64> for f128 {
#[inline]
fn cast(self) -> f64 { self as f64 }
}
#[unstable(feature = "float_conversions", issue = "159913")]
impl FloatToFloat<f128> for f128 {
#[inline]
fn cast(self) -> f128 { self as f128 }
}impl_float_to_float!(f128 => f16, f32, f64, f128);
113
114macro_rules! impl_from_bool {
116 ($($int:ty)*) => {$(
117 #[stable(feature = "from_bool", since = "1.28.0")]
118 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
119 const impl From<bool> for $int {
120 #[doc = concat!("[`", stringify!($int), "`]")]
122 #[doc = concat!("assert_eq!(", stringify!($int), "::from(false), 0);")]
128 #[doc = concat!("assert_eq!(", stringify!($int), "::from(true), 1);")]
130 #[inline(always)]
132 fn from(b: bool) -> Self {
133 b as Self
134 }
135 }
136 )*}
137}
138
139#[stable(feature = "from_bool", since = "1.28.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl From<bool> for u8 {
#[doc = "[`u8`]"]
#[doc = "assert_eq!(u8::from(false), 0);"]
#[doc = "assert_eq!(u8::from(true), 1);"]
#[inline(always)]
fn from(b: bool) -> Self { b as Self }
}
#[stable(feature = "from_bool", since = "1.28.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl From<bool> for u16 {
#[doc = "[`u16`]"]
#[doc = "assert_eq!(u16::from(false), 0);"]
#[doc = "assert_eq!(u16::from(true), 1);"]
#[inline(always)]
fn from(b: bool) -> Self { b as Self }
}
#[stable(feature = "from_bool", since = "1.28.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl From<bool> for u32 {
#[doc = "[`u32`]"]
#[doc = "assert_eq!(u32::from(false), 0);"]
#[doc = "assert_eq!(u32::from(true), 1);"]
#[inline(always)]
fn from(b: bool) -> Self { b as Self }
}
#[stable(feature = "from_bool", since = "1.28.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl From<bool> for u64 {
#[doc = "[`u64`]"]
#[doc = "assert_eq!(u64::from(false), 0);"]
#[doc = "assert_eq!(u64::from(true), 1);"]
#[inline(always)]
fn from(b: bool) -> Self { b as Self }
}
#[stable(feature = "from_bool", since = "1.28.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl From<bool> for u128 {
#[doc = "[`u128`]"]
#[doc = "assert_eq!(u128::from(false), 0);"]
#[doc = "assert_eq!(u128::from(true), 1);"]
#[inline(always)]
fn from(b: bool) -> Self { b as Self }
}
#[stable(feature = "from_bool", since = "1.28.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
141#[stable(feature = "from_bool", since = "1.28.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl From<bool> for i8 {
#[doc = "[`i8`]"]
#[doc = "assert_eq!(i8::from(false), 0);"]
#[doc = "assert_eq!(i8::from(true), 1);"]
#[inline(always)]
fn from(b: bool) -> Self { b as Self }
}
#[stable(feature = "from_bool", since = "1.28.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl From<bool> for i16 {
#[doc = "[`i16`]"]
#[doc = "assert_eq!(i16::from(false), 0);"]
#[doc = "assert_eq!(i16::from(true), 1);"]
#[inline(always)]
fn from(b: bool) -> Self { b as Self }
}
#[stable(feature = "from_bool", since = "1.28.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl From<bool> for i32 {
#[doc = "[`i32`]"]
#[doc = "assert_eq!(i32::from(false), 0);"]
#[doc = "assert_eq!(i32::from(true), 1);"]
#[inline(always)]
fn from(b: bool) -> Self { b as Self }
}
#[stable(feature = "from_bool", since = "1.28.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl From<bool> for i64 {
#[doc = "[`i64`]"]
#[doc = "assert_eq!(i64::from(false), 0);"]
#[doc = "assert_eq!(i64::from(true), 1);"]
#[inline(always)]
fn from(b: bool) -> Self { b as Self }
}
#[stable(feature = "from_bool", since = "1.28.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl From<bool> for i128 {
#[doc = "[`i128`]"]
#[doc = "assert_eq!(i128::from(false), 0);"]
#[doc = "assert_eq!(i128::from(true), 1);"]
#[inline(always)]
fn from(b: bool) -> Self { b as Self }
}
#[stable(feature = "from_bool", since = "1.28.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
142
143macro_rules! impl_from {
145 ($small:ty => $large:ty, $(#[$attrs:meta]),+) => {
146 $(#[$attrs])+
147 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
148 const impl From<$small> for $large {
149 #[doc = concat!("Converts from [`", stringify!($small), "`] to [`", stringify!($large), "`] losslessly.")]
150 #[inline(always)]
151 fn from(small: $small) -> Self {
152 debug_assert!(<$large>::MIN as i128 <= <$small>::MIN as i128);
153 debug_assert!(<$small>::MAX as u128 <= <$large>::MAX as u128);
154 small as Self
155 }
156 }
157 }
158}
159
160#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
162#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
163#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
164#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
165#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
166#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
167#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
168#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
169#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
170#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
171#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
172
173#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
175#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
176#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
177#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
178#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
179#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
180#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
181#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
182#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
183#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
184#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
185
186#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
188#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
189#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
190#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
191#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
192#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
193#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
194#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
195#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
196#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
197
198#[stable(feature = "lossless_iusize_conv", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
202#[stable(feature = "lossless_iusize_conv", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
203#[stable(feature = "lossless_iusize_conv", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
204
205#[unstable(feature = "f16", issue = "116909")]
#[unstable_feature_bound(f16)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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, #[unstable(feature = "f16", issue = "116909")], #[unstable_feature_bound(f16)]);
224#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
225#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
226#[unstable(feature = "f128", issue = "116909")]
#[unstable_feature_bound(f128)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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, #[unstable(feature = "f128", issue = "116909")], #[unstable_feature_bound(f128)]);
227#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
228#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
229#[unstable(feature = "f128", issue = "116909")]
#[unstable_feature_bound(f128)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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, #[unstable(feature = "f128", issue = "116909")], #[unstable_feature_bound(f128)]);
230#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
231#[unstable(feature = "f128", issue = "116909")]
#[unstable_feature_bound(f128)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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, #[unstable(feature = "f128", issue = "116909")], #[unstable_feature_bound(f128)]);
232#[unstable(feature = "f128", issue = "116909")]
#[unstable_feature_bound(f128)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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)]);
233
234#[unstable(feature = "f16", issue = "116909")]
#[unstable_feature_bound(f16)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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, #[unstable(feature = "f16", issue = "116909")], #[unstable_feature_bound(f16)]);
236#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
237#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
238#[unstable(feature = "f128", issue = "116909")]
#[unstable_feature_bound(f128)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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, #[unstable(feature = "f128", issue = "116909")], #[unstable_feature_bound(f128)]);
239#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
240#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
241#[unstable(feature = "f128", issue = "116909")]
#[unstable_feature_bound(f128)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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, #[unstable(feature = "f128", issue = "116909")], #[unstable_feature_bound(f128)]);
242#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
243#[unstable(feature = "f128", issue = "116909")]
#[unstable_feature_bound(f128)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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, #[unstable(feature = "f128", issue = "116909")], #[unstable_feature_bound(f128)]);
244#[unstable(feature = "f128", issue = "116909")]
#[unstable_feature_bound(f128)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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)]);
245
246#[unstable(feature = "f32_from_f16", issue = "154005")]
#[unstable_feature_bound(f32_from_f16)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl From<f16> for f32 {
#[doc = "Converts from [`f16`] to [`f32`] losslessly."]
#[inline(always)]
fn from(small: f16) -> Self {
if true {
if !(<f32>::MIN as i128 <= <f16>::MIN as i128) {
crate::panicking::panic("assertion failed: <f32>::MIN as i128 <= <f16>::MIN as i128")
};
};
if true {
if !(<f16>::MAX as u128 <= <f32>::MAX as u128) {
crate::panicking::panic("assertion failed: <f16>::MAX as u128 <= <f32>::MAX as u128")
};
};
small as Self
}
}impl_from!(f16 => f32, #[unstable(feature = "f32_from_f16", issue = "154005")], #[unstable_feature_bound(f32_from_f16)]);
255#[unstable(feature = "f16", issue = "116909")]
#[unstable_feature_bound(f16)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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, #[unstable(feature = "f16", issue = "116909")], #[unstable_feature_bound(f16)]);
256#[unstable(feature = "f128", issue = "116909")]
#[unstable_feature_bound(f16, f128)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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, #[unstable(feature = "f128", issue = "116909")], #[unstable_feature_bound(f16, f128)]);
258#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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")]);
259#[unstable(feature = "f128", issue = "116909")]
#[unstable_feature_bound(f128)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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, #[unstable(feature = "f128", issue = "116909")], #[unstable_feature_bound(f128)]);
260#[unstable(feature = "f128", issue = "116909")]
#[unstable_feature_bound(f128)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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, #[unstable(feature = "f128", issue = "116909")], #[unstable_feature_bound(f128)]);
261
262macro_rules! impl_float_from_bool {
263 (
264 $(#[$attr:meta])*
265 $float:ty $(;
266 doctest_prefix: $(#[doc = $doctest_prefix:literal])*
267 doctest_suffix: $(#[doc = $doctest_suffix:literal])*
268 )?
269 ) => {
270 $(#[$attr])*
271 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
272 const impl From<bool> for $float {
273 #[doc = concat!("Converts a [`bool`] to [`", stringify!($float),"`] losslessly.")]
274 $($(#[doc = $doctest_prefix])*)?
279 #[doc = concat!("let x = ", stringify!($float), "::from(false);")]
280 #[doc = concat!("let y = ", stringify!($float), "::from(true);")]
284 $($(#[doc = $doctest_suffix])*)?
286 #[inline]
288 fn from(small: bool) -> Self {
289 small as u8 as Self
290 }
291 }
292 };
293}
294
295#[unstable(feature = "f16", issue = "116909")]
#[unstable_feature_bound(f16)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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!(
297 #[unstable(feature = "f16", issue = "116909")]
298 #[unstable_feature_bound(f16)]
299 f16;
300 doctest_prefix:
301 doctest_suffix:
307 );
309#[stable(feature = "float_from_bool", since = "1.68.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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!(
310 #[stable(feature = "float_from_bool", since = "1.68.0")]
311 f32
312);
313#[stable(feature = "float_from_bool", since = "1.68.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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!(
314 #[stable(feature = "float_from_bool", since = "1.68.0")]
315 f64
316);
317#[unstable(feature = "f128", issue = "116909")]
#[unstable_feature_bound(f128)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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!(
318 #[unstable(feature = "f128", issue = "116909")]
319 #[unstable_feature_bound(f128)]
320 f128;
321 doctest_prefix:
322 doctest_suffix:
327 );
329
330macro_rules! impl_try_from_unbounded {
332 ($source:ty => $($target:ty),+) => {$(
333 #[stable(feature = "try_from", since = "1.34.0")]
334 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
335 const impl TryFrom<$source> for $target {
336 type Error = TryFromIntError;
337
338 #[inline]
341 fn try_from(value: $source) -> Result<Self, Self::Error> {
342 Ok(value as Self)
343 }
344 }
345 )*}
346}
347
348macro_rules! impl_try_from_lower_bounded {
350 ($source:ty => $($target:ty),+) => {$(
351 #[stable(feature = "try_from", since = "1.34.0")]
352 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
353 const impl TryFrom<$source> for $target {
354 type Error = TryFromIntError;
355
356 #[doc = concat!("is less than [`", stringify!($target), "::MIN`].")]
359 #[inline]
360 fn try_from(u: $source) -> Result<Self, Self::Error> {
361 if u >= 0 {
362 Ok(u as Self)
363 } else {
364 Err(TryFromIntError(IntErrorKind::NegOverflow))
365 }
366 }
367 }
368 )*}
369}
370
371macro_rules! impl_try_from_upper_bounded {
373 ($source:ty => $($target:ty),+) => {$(
374 #[stable(feature = "try_from", since = "1.34.0")]
375 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
376 const impl TryFrom<$source> for $target {
377 type Error = TryFromIntError;
378
379 #[doc = concat!("is greater than [`", stringify!($target), "::MAX`].")]
382 #[inline]
383 fn try_from(u: $source) -> Result<Self, Self::Error> {
384 if u > (Self::MAX as $source) {
385 Err(TryFromIntError(IntErrorKind::PosOverflow))
386 } else {
387 Ok(u as Self)
388 }
389 }
390 }
391 )*}
392}
393
394macro_rules! impl_try_from_both_bounded {
396 ($source:ty => $($target:ty),+) => {$(
397 #[stable(feature = "try_from", since = "1.34.0")]
398 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
399 const impl TryFrom<$source> for $target {
400 type Error = TryFromIntError;
401
402 #[inline]
406 fn try_from(u: $source) -> Result<Self, Self::Error> {
407 let min = Self::MIN as $source;
408 let max = Self::MAX as $source;
409 if u < min {
410 Err(TryFromIntError(IntErrorKind::NegOverflow))
411 } else if u > max {
412 Err(TryFromIntError(IntErrorKind::PosOverflow))
413 } else {
414 Ok(u as Self)
415 }
416 }
417 }
418 )*}
419}
420
421macro_rules! impl_try_from_integer_for_bool {
423 ($signedness:ident $($int:ty)+) => {$(
424 #[stable(feature = "bool_try_from_int", since = "1.95.0")]
425 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
426 const impl TryFrom<$int> for bool {
427 type Error = TryFromIntError;
428
429 #[doc = concat!("assert_eq!(bool::try_from(0_", stringify!($int), "), Ok(false));")]
436 #[doc = concat!("assert_eq!(bool::try_from(1_", stringify!($int), "), Ok(true));")]
438 #[doc = concat!("assert!(bool::try_from(2_", stringify!($int), ").is_err());")]
440 #[inline]
442 fn try_from(i: $int) -> Result<Self, Self::Error> {
443 sign_dependent_expr!{
444 $signedness ?
445 if signed {
446 match i {
447 0 => Ok(false),
448 1 => Ok(true),
449 ..0 => Err(TryFromIntError(IntErrorKind::NegOverflow)),
450 2.. => Err(TryFromIntError(IntErrorKind::PosOverflow)),
451 }
452 }
453 if unsigned {
454 match i {
455 0 => Ok(false),
456 1 => Ok(true),
457 2.. => Err(TryFromIntError(IntErrorKind::PosOverflow)),
458 }
459 }
460 }
461 }
462 }
463 )*}
464}
465
466macro_rules! rev {
467 ($mac:ident, $source:ty => $($target:ty),+) => {$(
468 $mac!($target => $source);
469 )*}
470}
471
472#[stable(feature = "bool_try_from_int", since = "1.95.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u128> for bool {
type Error = TryFromIntError;
#[doc = "assert_eq!(bool::try_from(0_u128), Ok(false));"]
#[doc = "assert_eq!(bool::try_from(1_u128), Ok(true));"]
#[doc = "assert!(bool::try_from(2_u128).is_err());"]
#[inline]
fn try_from(i: u128) -> Result<Self, Self::Error> {
match i {
0 => Ok(false),
1 => Ok(true),
2.. => Err(TryFromIntError(IntErrorKind::PosOverflow)),
}
}
}
#[stable(feature = "bool_try_from_int", since = "1.95.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u64> for bool {
type Error = TryFromIntError;
#[doc = "assert_eq!(bool::try_from(0_u64), Ok(false));"]
#[doc = "assert_eq!(bool::try_from(1_u64), Ok(true));"]
#[doc = "assert!(bool::try_from(2_u64).is_err());"]
#[inline]
fn try_from(i: u64) -> Result<Self, Self::Error> {
match i {
0 => Ok(false),
1 => Ok(true),
2.. => Err(TryFromIntError(IntErrorKind::PosOverflow)),
}
}
}
#[stable(feature = "bool_try_from_int", since = "1.95.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u32> for bool {
type Error = TryFromIntError;
#[doc = "assert_eq!(bool::try_from(0_u32), Ok(false));"]
#[doc = "assert_eq!(bool::try_from(1_u32), Ok(true));"]
#[doc = "assert!(bool::try_from(2_u32).is_err());"]
#[inline]
fn try_from(i: u32) -> Result<Self, Self::Error> {
match i {
0 => Ok(false),
1 => Ok(true),
2.. => Err(TryFromIntError(IntErrorKind::PosOverflow)),
}
}
}
#[stable(feature = "bool_try_from_int", since = "1.95.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u16> for bool {
type Error = TryFromIntError;
#[doc = "assert_eq!(bool::try_from(0_u16), Ok(false));"]
#[doc = "assert_eq!(bool::try_from(1_u16), Ok(true));"]
#[doc = "assert!(bool::try_from(2_u16).is_err());"]
#[inline]
fn try_from(i: u16) -> Result<Self, Self::Error> {
match i {
0 => Ok(false),
1 => Ok(true),
2.. => Err(TryFromIntError(IntErrorKind::PosOverflow)),
}
}
}
#[stable(feature = "bool_try_from_int", since = "1.95.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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),
2.. => Err(TryFromIntError(IntErrorKind::PosOverflow)),
}
}
}impl_try_from_integer_for_bool!(unsigned u128 u64 u32 u16 u8);
474#[stable(feature = "bool_try_from_int", since = "1.95.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i128> for bool {
type Error = TryFromIntError;
#[doc = "assert_eq!(bool::try_from(0_i128), Ok(false));"]
#[doc = "assert_eq!(bool::try_from(1_i128), Ok(true));"]
#[doc = "assert!(bool::try_from(2_i128).is_err());"]
#[inline]
fn try_from(i: i128) -> Result<Self, Self::Error> {
match i {
0 => Ok(false),
1 => Ok(true),
..0 => Err(TryFromIntError(IntErrorKind::NegOverflow)),
2.. => Err(TryFromIntError(IntErrorKind::PosOverflow)),
}
}
}
#[stable(feature = "bool_try_from_int", since = "1.95.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i64> for bool {
type Error = TryFromIntError;
#[doc = "assert_eq!(bool::try_from(0_i64), Ok(false));"]
#[doc = "assert_eq!(bool::try_from(1_i64), Ok(true));"]
#[doc = "assert!(bool::try_from(2_i64).is_err());"]
#[inline]
fn try_from(i: i64) -> Result<Self, Self::Error> {
match i {
0 => Ok(false),
1 => Ok(true),
..0 => Err(TryFromIntError(IntErrorKind::NegOverflow)),
2.. => Err(TryFromIntError(IntErrorKind::PosOverflow)),
}
}
}
#[stable(feature = "bool_try_from_int", since = "1.95.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i32> for bool {
type Error = TryFromIntError;
#[doc = "assert_eq!(bool::try_from(0_i32), Ok(false));"]
#[doc = "assert_eq!(bool::try_from(1_i32), Ok(true));"]
#[doc = "assert!(bool::try_from(2_i32).is_err());"]
#[inline]
fn try_from(i: i32) -> Result<Self, Self::Error> {
match i {
0 => Ok(false),
1 => Ok(true),
..0 => Err(TryFromIntError(IntErrorKind::NegOverflow)),
2.. => Err(TryFromIntError(IntErrorKind::PosOverflow)),
}
}
}
#[stable(feature = "bool_try_from_int", since = "1.95.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i16> for bool {
type Error = TryFromIntError;
#[doc = "assert_eq!(bool::try_from(0_i16), Ok(false));"]
#[doc = "assert_eq!(bool::try_from(1_i16), Ok(true));"]
#[doc = "assert!(bool::try_from(2_i16).is_err());"]
#[inline]
fn try_from(i: i16) -> Result<Self, Self::Error> {
match i {
0 => Ok(false),
1 => Ok(true),
..0 => Err(TryFromIntError(IntErrorKind::NegOverflow)),
2.. => Err(TryFromIntError(IntErrorKind::PosOverflow)),
}
}
}
#[stable(feature = "bool_try_from_int", since = "1.95.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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),
..0 => Err(TryFromIntError(IntErrorKind::NegOverflow)),
2.. => Err(TryFromIntError(IntErrorKind::PosOverflow)),
}
}
}impl_try_from_integer_for_bool!(signed i128 i64 i32 i16 i8);
475
476#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u16> for u8 {
type Error = TryFromIntError;
#[doc = "is greater than [`u8::MAX`]."]
#[inline]
fn try_from(u: u16) -> Result<Self, Self::Error> {
if u > (Self::MAX as u16) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(u16 => u8);
478#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u32> for u8 {
type Error = TryFromIntError;
#[doc = "is greater than [`u8::MAX`]."]
#[inline]
fn try_from(u: u32) -> Result<Self, Self::Error> {
if u > (Self::MAX as u32) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u32> for u16 {
type Error = TryFromIntError;
#[doc = "is greater than [`u16::MAX`]."]
#[inline]
fn try_from(u: u32) -> Result<Self, Self::Error> {
if u > (Self::MAX as u32) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(u32 => u8, u16);
479#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u64> for u8 {
type Error = TryFromIntError;
#[doc = "is greater than [`u8::MAX`]."]
#[inline]
fn try_from(u: u64) -> Result<Self, Self::Error> {
if u > (Self::MAX as u64) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u64> for u16 {
type Error = TryFromIntError;
#[doc = "is greater than [`u16::MAX`]."]
#[inline]
fn try_from(u: u64) -> Result<Self, Self::Error> {
if u > (Self::MAX as u64) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u64> for u32 {
type Error = TryFromIntError;
#[doc = "is greater than [`u32::MAX`]."]
#[inline]
fn try_from(u: u64) -> Result<Self, Self::Error> {
if u > (Self::MAX as u64) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(u64 => u8, u16, u32);
480#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u128> for u8 {
type Error = TryFromIntError;
#[doc = "is greater than [`u8::MAX`]."]
#[inline]
fn try_from(u: u128) -> Result<Self, Self::Error> {
if u > (Self::MAX as u128) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u128> for u16 {
type Error = TryFromIntError;
#[doc = "is greater than [`u16::MAX`]."]
#[inline]
fn try_from(u: u128) -> Result<Self, Self::Error> {
if u > (Self::MAX as u128) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u128> for u32 {
type Error = TryFromIntError;
#[doc = "is greater than [`u32::MAX`]."]
#[inline]
fn try_from(u: u128) -> Result<Self, Self::Error> {
if u > (Self::MAX as u128) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u128> for u64 {
type Error = TryFromIntError;
#[doc = "is greater than [`u64::MAX`]."]
#[inline]
fn try_from(u: u128) -> Result<Self, Self::Error> {
if u > (Self::MAX as u128) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(u128 => u8, u16, u32, u64);
481
482#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_both_bounded!(i16 => i8);
484#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i32> for i8 {
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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_both_bounded!(i32 => i8, i16);
485#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i64> for i8 {
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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i64> for i16 {
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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_both_bounded!(i64 => i8, i16, i32);
486#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i128> for i8 {
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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i128> for i16 {
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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i128> for i32 {
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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_both_bounded!(i128 => i8, i16, i32, i64);
487
488#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u8> for i8 {
type Error = TryFromIntError;
#[doc = "is greater than [`i8::MAX`]."]
#[inline]
fn try_from(u: u8) -> Result<Self, Self::Error> {
if u > (Self::MAX as u8) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(u8 => i8);
490#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u16> for i8 {
type Error = TryFromIntError;
#[doc = "is greater than [`i8::MAX`]."]
#[inline]
fn try_from(u: u16) -> Result<Self, Self::Error> {
if u > (Self::MAX as u16) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u16> for i16 {
type Error = TryFromIntError;
#[doc = "is greater than [`i16::MAX`]."]
#[inline]
fn try_from(u: u16) -> Result<Self, Self::Error> {
if u > (Self::MAX as u16) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(u16 => i8, i16);
491#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u32> for i8 {
type Error = TryFromIntError;
#[doc = "is greater than [`i8::MAX`]."]
#[inline]
fn try_from(u: u32) -> Result<Self, Self::Error> {
if u > (Self::MAX as u32) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u32> for i16 {
type Error = TryFromIntError;
#[doc = "is greater than [`i16::MAX`]."]
#[inline]
fn try_from(u: u32) -> Result<Self, Self::Error> {
if u > (Self::MAX as u32) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u32> for i32 {
type Error = TryFromIntError;
#[doc = "is greater than [`i32::MAX`]."]
#[inline]
fn try_from(u: u32) -> Result<Self, Self::Error> {
if u > (Self::MAX as u32) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(u32 => i8, i16, i32);
492#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u64> for i8 {
type Error = TryFromIntError;
#[doc = "is greater than [`i8::MAX`]."]
#[inline]
fn try_from(u: u64) -> Result<Self, Self::Error> {
if u > (Self::MAX as u64) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u64> for i16 {
type Error = TryFromIntError;
#[doc = "is greater than [`i16::MAX`]."]
#[inline]
fn try_from(u: u64) -> Result<Self, Self::Error> {
if u > (Self::MAX as u64) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u64> for i32 {
type Error = TryFromIntError;
#[doc = "is greater than [`i32::MAX`]."]
#[inline]
fn try_from(u: u64) -> Result<Self, Self::Error> {
if u > (Self::MAX as u64) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u64> for i64 {
type Error = TryFromIntError;
#[doc = "is greater than [`i64::MAX`]."]
#[inline]
fn try_from(u: u64) -> Result<Self, Self::Error> {
if u > (Self::MAX as u64) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(u64 => i8, i16, i32, i64);
493#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u128> for i8 {
type Error = TryFromIntError;
#[doc = "is greater than [`i8::MAX`]."]
#[inline]
fn try_from(u: u128) -> Result<Self, Self::Error> {
if u > (Self::MAX as u128) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u128> for i16 {
type Error = TryFromIntError;
#[doc = "is greater than [`i16::MAX`]."]
#[inline]
fn try_from(u: u128) -> Result<Self, Self::Error> {
if u > (Self::MAX as u128) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u128> for i32 {
type Error = TryFromIntError;
#[doc = "is greater than [`i32::MAX`]."]
#[inline]
fn try_from(u: u128) -> Result<Self, Self::Error> {
if u > (Self::MAX as u128) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u128> for i64 {
type Error = TryFromIntError;
#[doc = "is greater than [`i64::MAX`]."]
#[inline]
fn try_from(u: u128) -> Result<Self, Self::Error> {
if u > (Self::MAX as u128) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u128> for i128 {
type Error = TryFromIntError;
#[doc = "is greater than [`i128::MAX`]."]
#[inline]
fn try_from(u: u128) -> Result<Self, Self::Error> {
if u > (Self::MAX as u128) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(u128 => i8, i16, i32, i64, i128);
494
495#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i8> for u8 {
type Error = TryFromIntError;
#[doc = "is less than [`u8::MIN`]."]
#[inline]
fn try_from(u: i8) -> Result<Self, Self::Error> {
if u >= 0 {
Ok(u as Self)
} else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i8> for u16 {
type Error = TryFromIntError;
#[doc = "is less than [`u16::MIN`]."]
#[inline]
fn try_from(u: i8) -> Result<Self, Self::Error> {
if u >= 0 {
Ok(u as Self)
} else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i8> for u32 {
type Error = TryFromIntError;
#[doc = "is less than [`u32::MIN`]."]
#[inline]
fn try_from(u: i8) -> Result<Self, Self::Error> {
if u >= 0 {
Ok(u as Self)
} else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i8> for u64 {
type Error = TryFromIntError;
#[doc = "is less than [`u64::MIN`]."]
#[inline]
fn try_from(u: i8) -> Result<Self, Self::Error> {
if u >= 0 {
Ok(u as Self)
} else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i8> for u128 {
type Error = TryFromIntError;
#[doc = "is less than [`u128::MIN`]."]
#[inline]
fn try_from(u: i8) -> Result<Self, Self::Error> {
if u >= 0 {
Ok(u as Self)
} else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
}
}impl_try_from_lower_bounded!(i8 => u8, u16, u32, u64, u128);
497#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_both_bounded!(i16 => u8);
498#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i16> for u16 {
type Error = TryFromIntError;
#[doc = "is less than [`u16::MIN`]."]
#[inline]
fn try_from(u: i16) -> Result<Self, Self::Error> {
if u >= 0 {
Ok(u as Self)
} else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i16> for u32 {
type Error = TryFromIntError;
#[doc = "is less than [`u32::MIN`]."]
#[inline]
fn try_from(u: i16) -> Result<Self, Self::Error> {
if u >= 0 {
Ok(u as Self)
} else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i16> for u64 {
type Error = TryFromIntError;
#[doc = "is less than [`u64::MIN`]."]
#[inline]
fn try_from(u: i16) -> Result<Self, Self::Error> {
if u >= 0 {
Ok(u as Self)
} else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i16> for u128 {
type Error = TryFromIntError;
#[doc = "is less than [`u128::MIN`]."]
#[inline]
fn try_from(u: i16) -> Result<Self, Self::Error> {
if u >= 0 {
Ok(u as Self)
} else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
}
}impl_try_from_lower_bounded!(i16 => u16, u32, u64, u128);
499#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i32> for u8 {
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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_both_bounded!(i32 => u8, u16);
500#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i32> for u32 {
type Error = TryFromIntError;
#[doc = "is less than [`u32::MIN`]."]
#[inline]
fn try_from(u: i32) -> Result<Self, Self::Error> {
if u >= 0 {
Ok(u as Self)
} else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i32> for u64 {
type Error = TryFromIntError;
#[doc = "is less than [`u64::MIN`]."]
#[inline]
fn try_from(u: i32) -> Result<Self, Self::Error> {
if u >= 0 {
Ok(u as Self)
} else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i32> for u128 {
type Error = TryFromIntError;
#[doc = "is less than [`u128::MIN`]."]
#[inline]
fn try_from(u: i32) -> Result<Self, Self::Error> {
if u >= 0 {
Ok(u as Self)
} else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
}
}impl_try_from_lower_bounded!(i32 => u32, u64, u128);
501#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i64> for u8 {
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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i64> for u16 {
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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_both_bounded!(i64 => u8, u16, u32);
502#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i64> for u64 {
type Error = TryFromIntError;
#[doc = "is less than [`u64::MIN`]."]
#[inline]
fn try_from(u: i64) -> Result<Self, Self::Error> {
if u >= 0 {
Ok(u as Self)
} else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i64> for u128 {
type Error = TryFromIntError;
#[doc = "is less than [`u128::MIN`]."]
#[inline]
fn try_from(u: i64) -> Result<Self, Self::Error> {
if u >= 0 {
Ok(u as Self)
} else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
}
}impl_try_from_lower_bounded!(i64 => u64, u128);
503#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i128> for u8 {
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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i128> for u16 {
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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i128> for u32 {
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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_both_bounded!(i128 => u8, u16, u32, u64);
504#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i128> for u128 {
type Error = TryFromIntError;
#[doc = "is less than [`u128::MIN`]."]
#[inline]
fn try_from(u: i128) -> Result<Self, Self::Error> {
if u >= 0 {
Ok(u as Self)
} else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
}
}impl_try_from_lower_bounded!(i128 => u128);
505
506#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<usize> for isize {
type Error = TryFromIntError;
#[doc = "is greater than [`isize::MAX`]."]
#[inline]
fn try_from(u: usize) -> Result<Self, Self::Error> {
if u > (Self::MAX as usize) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(usize => isize);
508#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<isize> for usize {
type Error = TryFromIntError;
#[doc = "is less than [`usize::MIN`]."]
#[inline]
fn try_from(u: isize) -> Result<Self, Self::Error> {
if u >= 0 {
Ok(u as Self)
} else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
}
}impl_try_from_lower_bounded!(isize => usize);
509
510#[cfg(target_pointer_width = "16")]
511mod ptr_try_from_impls {
512 use super::{IntErrorKind, TryFromIntError};
513
514 impl_try_from_upper_bounded!(usize => u8);
515 impl_try_from_unbounded!(usize => u16, u32, u64, u128);
516 impl_try_from_upper_bounded!(usize => i8, i16);
517 impl_try_from_unbounded!(usize => i32, i64, i128);
518
519 impl_try_from_both_bounded!(isize => u8);
520 impl_try_from_lower_bounded!(isize => u16, u32, u64, u128);
521 impl_try_from_both_bounded!(isize => i8);
522 impl_try_from_unbounded!(isize => i16, i32, i64, i128);
523
524 rev!(impl_try_from_upper_bounded, usize => u32, u64, u128);
525 rev!(impl_try_from_lower_bounded, usize => i8, i16);
526 rev!(impl_try_from_both_bounded, usize => i32, i64, i128);
527
528 rev!(impl_try_from_upper_bounded, isize => u16, u32, u64, u128);
529 rev!(impl_try_from_both_bounded, isize => i32, i64, i128);
530}
531
532#[cfg(target_pointer_width = "32")]
533mod ptr_try_from_impls {
534 use super::{IntErrorKind, TryFromIntError};
535
536 impl_try_from_upper_bounded!(usize => u8, u16);
537 impl_try_from_unbounded!(usize => u32, u64, u128);
538 impl_try_from_upper_bounded!(usize => i8, i16, i32);
539 impl_try_from_unbounded!(usize => i64, i128);
540
541 impl_try_from_both_bounded!(isize => u8, u16);
542 impl_try_from_lower_bounded!(isize => u32, u64, u128);
543 impl_try_from_both_bounded!(isize => i8, i16);
544 impl_try_from_unbounded!(isize => i32, i64, i128);
545
546 rev!(impl_try_from_unbounded, usize => u32);
547 rev!(impl_try_from_upper_bounded, usize => u64, u128);
548 rev!(impl_try_from_lower_bounded, usize => i8, i16, i32);
549 rev!(impl_try_from_both_bounded, usize => i64, i128);
550
551 rev!(impl_try_from_unbounded, isize => u16);
552 rev!(impl_try_from_upper_bounded, isize => u32, u64, u128);
553 rev!(impl_try_from_unbounded, isize => i32);
554 rev!(impl_try_from_both_bounded, isize => i64, i128);
555}
556
557#[cfg(target_pointer_width = "64")]
558mod ptr_try_from_impls {
559 use super::{IntErrorKind, TryFromIntError};
560
561 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<usize> for u8 {
type Error = TryFromIntError;
#[doc = "is greater than [`u8::MAX`]."]
#[inline]
fn try_from(u: usize) -> Result<Self, Self::Error> {
if u > (Self::MAX as usize) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<usize> for u16 {
type Error = TryFromIntError;
#[doc = "is greater than [`u16::MAX`]."]
#[inline]
fn try_from(u: usize) -> Result<Self, Self::Error> {
if u > (Self::MAX as usize) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<usize> for u32 {
type Error = TryFromIntError;
#[doc = "is greater than [`u32::MAX`]."]
#[inline]
fn try_from(u: usize) -> Result<Self, Self::Error> {
if u > (Self::MAX as usize) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(usize => u8, u16, u32);
562 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<usize> for u64 {
type Error = TryFromIntError;
#[inline]
fn try_from(value: usize) -> Result<Self, Self::Error> {
Ok(value as Self)
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
563 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<usize> for i8 {
type Error = TryFromIntError;
#[doc = "is greater than [`i8::MAX`]."]
#[inline]
fn try_from(u: usize) -> Result<Self, Self::Error> {
if u > (Self::MAX as usize) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<usize> for i16 {
type Error = TryFromIntError;
#[doc = "is greater than [`i16::MAX`]."]
#[inline]
fn try_from(u: usize) -> Result<Self, Self::Error> {
if u > (Self::MAX as usize) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<usize> for i32 {
type Error = TryFromIntError;
#[doc = "is greater than [`i32::MAX`]."]
#[inline]
fn try_from(u: usize) -> Result<Self, Self::Error> {
if u > (Self::MAX as usize) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<usize> for i64 {
type Error = TryFromIntError;
#[doc = "is greater than [`i64::MAX`]."]
#[inline]
fn try_from(u: usize) -> Result<Self, Self::Error> {
if u > (Self::MAX as usize) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_upper_bounded!(usize => i8, i16, i32, i64);
564 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
565
566 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<isize> for u8 {
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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<isize> for u16 {
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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_both_bounded!(isize => u8, u16, u32);
567 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<isize> for u64 {
type Error = TryFromIntError;
#[doc = "is less than [`u64::MIN`]."]
#[inline]
fn try_from(u: isize) -> Result<Self, Self::Error> {
if u >= 0 {
Ok(u as Self)
} else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<isize> for u128 {
type Error = TryFromIntError;
#[doc = "is less than [`u128::MIN`]."]
#[inline]
fn try_from(u: isize) -> Result<Self, Self::Error> {
if u >= 0 {
Ok(u as Self)
} else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
}
}impl_try_from_lower_bounded!(isize => u64, u128);
568 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<isize> for i8 {
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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<isize> for i16 {
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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}impl_try_from_both_bounded!(isize => i8, i16, i32);
569 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<isize> for i64 {
type Error = TryFromIntError;
#[inline]
fn try_from(value: isize) -> Result<Self, Self::Error> {
Ok(value as Self)
}
}
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
570
571 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
572 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u128> for usize {
type Error = TryFromIntError;
#[doc = "is greater than [`usize::MAX`]."]
#[inline]
fn try_from(u: u128) -> Result<Self, Self::Error> {
if u > (Self::MAX as u128) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}rev!(impl_try_from_upper_bounded, usize => u128);
573 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<i64> for usize {
type Error = TryFromIntError;
#[doc = "is less than [`usize::MIN`]."]
#[inline]
fn try_from(u: i64) -> Result<Self, Self::Error> {
if u >= 0 {
Ok(u as Self)
} else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
}
}rev!(impl_try_from_lower_bounded, usize => i8, i16, i32, i64);
574 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}rev!(impl_try_from_both_bounded, usize => i128);
575
576 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
577 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<u128> for isize {
type Error = TryFromIntError;
#[doc = "is greater than [`isize::MAX`]."]
#[inline]
fn try_from(u: u128) -> Result<Self, Self::Error> {
if u > (Self::MAX as u128) {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}rev!(impl_try_from_upper_bounded, isize => u64, u128);
578 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
579 #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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 {
Err(TryFromIntError(IntErrorKind::NegOverflow))
} else if u > max {
Err(TryFromIntError(IntErrorKind::PosOverflow))
} else { Ok(u as Self) }
}
}rev!(impl_try_from_both_bounded, isize => i128);
580}
581
582use crate::num::NonZero;
584
585macro_rules! impl_nonzero_int_from_nonzero_int {
586 ($Small:ty => $Large:ty) => {
587 #[stable(feature = "nz_int_conv", since = "1.41.0")]
588 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
589 const impl From<NonZero<$Small>> for NonZero<$Large> {
590 #[doc = concat!("Converts <code>[NonZero]\\<[", stringify!($Small), "]></code> ")]
593 #[doc = concat!("to <code>[NonZero]\\<[", stringify!($Large), "]></code> losslessly.")]
594 #[inline]
595 fn from(small: NonZero<$Small>) -> Self {
596 unsafe { Self::new_unchecked(From::from(small.get())) }
598 }
599 }
600 };
601}
602
603#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
605#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
606#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
607#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
608#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
609#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
610#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
611#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
612#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
613#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
614#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
615#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
616
617#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
619#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
620#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
621#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
622#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
623#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
624#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
625#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
626#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
627#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
628#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
629#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
630
631#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
633#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
634#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
635#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
636#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
637#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
638#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
639#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
640#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
641#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
642#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
643
644macro_rules! impl_nonzero_int_try_from_int {
645 ($Int:ty) => {
646 #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
647 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
648 const impl TryFrom<$Int> for NonZero<$Int> {
649 type Error = TryFromIntError;
650
651 #[doc = concat!("Attempts to convert [`", stringify!($Int), "`] ")]
654 #[doc = concat!("to <code>[NonZero]\\<[", stringify!($Int), "]></code>.")]
655 #[inline]
656 fn try_from(value: $Int) -> Result<Self, Self::Error> {
657 Self::new(value).ok_or(TryFromIntError(IntErrorKind::Zero))
658 }
659 }
660 };
661}
662
663#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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(IntErrorKind::Zero))
}
}impl_nonzero_int_try_from_int!(u8);
665#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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(IntErrorKind::Zero))
}
}impl_nonzero_int_try_from_int!(u16);
666#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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(IntErrorKind::Zero))
}
}impl_nonzero_int_try_from_int!(u32);
667#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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(IntErrorKind::Zero))
}
}impl_nonzero_int_try_from_int!(u64);
668#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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(IntErrorKind::Zero))
}
}impl_nonzero_int_try_from_int!(u128);
669#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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(IntErrorKind::Zero))
}
}impl_nonzero_int_try_from_int!(usize);
670#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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(IntErrorKind::Zero))
}
}impl_nonzero_int_try_from_int!(i8);
671#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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(IntErrorKind::Zero))
}
}impl_nonzero_int_try_from_int!(i16);
672#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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(IntErrorKind::Zero))
}
}impl_nonzero_int_try_from_int!(i32);
673#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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(IntErrorKind::Zero))
}
}impl_nonzero_int_try_from_int!(i64);
674#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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(IntErrorKind::Zero))
}
}impl_nonzero_int_try_from_int!(i128);
675#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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(IntErrorKind::Zero))
}
}impl_nonzero_int_try_from_int!(isize);
676
677macro_rules! impl_nonzero_int_try_from_nonzero_int {
678 ($source:ty => $($target:ty),+) => {$(
679 #[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
680 #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
681 const impl TryFrom<NonZero<$source>> for NonZero<$target> {
682 type Error = TryFromIntError;
683
684 #[doc = concat!("Attempts to convert <code>[NonZero]\\<[", stringify!($source), "]></code> ")]
687 #[doc = concat!("to <code>[NonZero]\\<[", stringify!($target), "]></code>.")]
688 #[inline]
689 fn try_from(value: NonZero<$source>) -> Result<Self, Self::Error> {
690 Ok(unsafe { Self::new_unchecked(<$target>::try_from(value.get())?) })
692 }
693 }
694 )*};
695}
696
697#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
699#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u32>> for NonZero<u8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u32]></code> "]
#[doc = "to <code>[NonZero]\\<[u8]></code>."]
#[inline]
fn try_from(value: NonZero<u32>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u8>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u32>> for NonZero<u16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u32]></code> "]
#[doc = "to <code>[NonZero]\\<[u16]></code>."]
#[inline]
fn try_from(value: NonZero<u32>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u16>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
700#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u64>> for NonZero<u8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u64]></code> "]
#[doc = "to <code>[NonZero]\\<[u8]></code>."]
#[inline]
fn try_from(value: NonZero<u64>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u8>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u64>> for NonZero<u16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u64]></code> "]
#[doc = "to <code>[NonZero]\\<[u16]></code>."]
#[inline]
fn try_from(value: NonZero<u64>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u16>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u64>> for NonZero<u32> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u64]></code> "]
#[doc = "to <code>[NonZero]\\<[u32]></code>."]
#[inline]
fn try_from(value: NonZero<u64>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u32>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
701#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u128>> for NonZero<u8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u128]></code> "]
#[doc = "to <code>[NonZero]\\<[u8]></code>."]
#[inline]
fn try_from(value: NonZero<u128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u8>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u128>> for NonZero<u16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u128]></code> "]
#[doc = "to <code>[NonZero]\\<[u16]></code>."]
#[inline]
fn try_from(value: NonZero<u128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u16>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u128>> for NonZero<u32> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u128]></code> "]
#[doc = "to <code>[NonZero]\\<[u32]></code>."]
#[inline]
fn try_from(value: NonZero<u128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u32>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u128>> for NonZero<u64> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u128]></code> "]
#[doc = "to <code>[NonZero]\\<[u64]></code>."]
#[inline]
fn try_from(value: NonZero<u128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u64>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
702#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<usize>> for NonZero<u8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[usize]></code> "]
#[doc = "to <code>[NonZero]\\<[u8]></code>."]
#[inline]
fn try_from(value: NonZero<usize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u8>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<usize>> for NonZero<u16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[usize]></code> "]
#[doc = "to <code>[NonZero]\\<[u16]></code>."]
#[inline]
fn try_from(value: NonZero<usize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u16>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<usize>> for NonZero<u32> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[usize]></code> "]
#[doc = "to <code>[NonZero]\\<[u32]></code>."]
#[inline]
fn try_from(value: NonZero<usize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u32>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<usize>> for NonZero<u64> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[usize]></code> "]
#[doc = "to <code>[NonZero]\\<[u64]></code>."]
#[inline]
fn try_from(value: NonZero<usize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u64>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
703
704#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
706#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i32>> for NonZero<i8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i32]></code> "]
#[doc = "to <code>[NonZero]\\<[i8]></code>."]
#[inline]
fn try_from(value: NonZero<i32>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i8>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i32>> for NonZero<i16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i32]></code> "]
#[doc = "to <code>[NonZero]\\<[i16]></code>."]
#[inline]
fn try_from(value: NonZero<i32>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i16>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
707#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i64>> for NonZero<i8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i64]></code> "]
#[doc = "to <code>[NonZero]\\<[i8]></code>."]
#[inline]
fn try_from(value: NonZero<i64>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i8>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i64>> for NonZero<i16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i64]></code> "]
#[doc = "to <code>[NonZero]\\<[i16]></code>."]
#[inline]
fn try_from(value: NonZero<i64>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i16>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i64>> for NonZero<i32> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i64]></code> "]
#[doc = "to <code>[NonZero]\\<[i32]></code>."]
#[inline]
fn try_from(value: NonZero<i64>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i32>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
708#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i128>> for NonZero<i8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i128]></code> "]
#[doc = "to <code>[NonZero]\\<[i8]></code>."]
#[inline]
fn try_from(value: NonZero<i128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i8>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i128>> for NonZero<i16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i128]></code> "]
#[doc = "to <code>[NonZero]\\<[i16]></code>."]
#[inline]
fn try_from(value: NonZero<i128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i16>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i128>> for NonZero<i32> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i128]></code> "]
#[doc = "to <code>[NonZero]\\<[i32]></code>."]
#[inline]
fn try_from(value: NonZero<i128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i32>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i128>> for NonZero<i64> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i128]></code> "]
#[doc = "to <code>[NonZero]\\<[i64]></code>."]
#[inline]
fn try_from(value: NonZero<i128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i64>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
709#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<isize>> for NonZero<i8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[isize]></code> "]
#[doc = "to <code>[NonZero]\\<[i8]></code>."]
#[inline]
fn try_from(value: NonZero<isize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i8>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<isize>> for NonZero<i16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[isize]></code> "]
#[doc = "to <code>[NonZero]\\<[i16]></code>."]
#[inline]
fn try_from(value: NonZero<isize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i16>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<isize>> for NonZero<i32> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[isize]></code> "]
#[doc = "to <code>[NonZero]\\<[i32]></code>."]
#[inline]
fn try_from(value: NonZero<isize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i32>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<isize>> for NonZero<i64> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[isize]></code> "]
#[doc = "to <code>[NonZero]\\<[i64]></code>."]
#[inline]
fn try_from(value: NonZero<isize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i64>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
710
711#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
713#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u16>> for NonZero<i8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u16]></code> "]
#[doc = "to <code>[NonZero]\\<[i8]></code>."]
#[inline]
fn try_from(value: NonZero<u16>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i8>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u16>> for NonZero<i16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u16]></code> "]
#[doc = "to <code>[NonZero]\\<[i16]></code>."]
#[inline]
fn try_from(value: NonZero<u16>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i16>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
714#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u32>> for NonZero<i8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u32]></code> "]
#[doc = "to <code>[NonZero]\\<[i8]></code>."]
#[inline]
fn try_from(value: NonZero<u32>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i8>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u32>> for NonZero<i16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u32]></code> "]
#[doc = "to <code>[NonZero]\\<[i16]></code>."]
#[inline]
fn try_from(value: NonZero<u32>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i16>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u32>> for NonZero<i32> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u32]></code> "]
#[doc = "to <code>[NonZero]\\<[i32]></code>."]
#[inline]
fn try_from(value: NonZero<u32>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i32>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
715#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u64>> for NonZero<i8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u64]></code> "]
#[doc = "to <code>[NonZero]\\<[i8]></code>."]
#[inline]
fn try_from(value: NonZero<u64>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i8>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u64>> for NonZero<i16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u64]></code> "]
#[doc = "to <code>[NonZero]\\<[i16]></code>."]
#[inline]
fn try_from(value: NonZero<u64>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i16>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u64>> for NonZero<i32> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u64]></code> "]
#[doc = "to <code>[NonZero]\\<[i32]></code>."]
#[inline]
fn try_from(value: NonZero<u64>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i32>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u64>> for NonZero<i64> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u64]></code> "]
#[doc = "to <code>[NonZero]\\<[i64]></code>."]
#[inline]
fn try_from(value: NonZero<u64>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i64>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
716#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u128>> for NonZero<i8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u128]></code> "]
#[doc = "to <code>[NonZero]\\<[i8]></code>."]
#[inline]
fn try_from(value: NonZero<u128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i8>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u128>> for NonZero<i16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u128]></code> "]
#[doc = "to <code>[NonZero]\\<[i16]></code>."]
#[inline]
fn try_from(value: NonZero<u128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i16>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u128>> for NonZero<i32> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u128]></code> "]
#[doc = "to <code>[NonZero]\\<[i32]></code>."]
#[inline]
fn try_from(value: NonZero<u128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i32>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u128>> for NonZero<i64> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u128]></code> "]
#[doc = "to <code>[NonZero]\\<[i64]></code>."]
#[inline]
fn try_from(value: NonZero<u128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i64>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<u128>> for NonZero<i128> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[u128]></code> "]
#[doc = "to <code>[NonZero]\\<[i128]></code>."]
#[inline]
fn try_from(value: NonZero<u128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i128>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
717#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<usize>> for NonZero<i8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[usize]></code> "]
#[doc = "to <code>[NonZero]\\<[i8]></code>."]
#[inline]
fn try_from(value: NonZero<usize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i8>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<usize>> for NonZero<i16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[usize]></code> "]
#[doc = "to <code>[NonZero]\\<[i16]></code>."]
#[inline]
fn try_from(value: NonZero<usize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i16>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<usize>> for NonZero<i32> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[usize]></code> "]
#[doc = "to <code>[NonZero]\\<[i32]></code>."]
#[inline]
fn try_from(value: NonZero<usize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i32>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<usize>> for NonZero<i64> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[usize]></code> "]
#[doc = "to <code>[NonZero]\\<[i64]></code>."]
#[inline]
fn try_from(value: NonZero<usize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i64>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<usize>> for NonZero<i128> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[usize]></code> "]
#[doc = "to <code>[NonZero]\\<[i128]></code>."]
#[inline]
fn try_from(value: NonZero<usize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<i128>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
718
719#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i8>> for NonZero<u8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i8]></code> "]
#[doc = "to <code>[NonZero]\\<[u8]></code>."]
#[inline]
fn try_from(value: NonZero<i8>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u8>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i8>> for NonZero<u16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i8]></code> "]
#[doc = "to <code>[NonZero]\\<[u16]></code>."]
#[inline]
fn try_from(value: NonZero<i8>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u16>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i8>> for NonZero<u32> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i8]></code> "]
#[doc = "to <code>[NonZero]\\<[u32]></code>."]
#[inline]
fn try_from(value: NonZero<i8>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u32>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i8>> for NonZero<u64> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i8]></code> "]
#[doc = "to <code>[NonZero]\\<[u64]></code>."]
#[inline]
fn try_from(value: NonZero<i8>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u64>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i8>> for NonZero<u128> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i8]></code> "]
#[doc = "to <code>[NonZero]\\<[u128]></code>."]
#[inline]
fn try_from(value: NonZero<i8>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u128>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
721#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i16>> for NonZero<u8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i16]></code> "]
#[doc = "to <code>[NonZero]\\<[u8]></code>."]
#[inline]
fn try_from(value: NonZero<i16>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u8>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i16>> for NonZero<u16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i16]></code> "]
#[doc = "to <code>[NonZero]\\<[u16]></code>."]
#[inline]
fn try_from(value: NonZero<i16>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u16>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i16>> for NonZero<u32> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i16]></code> "]
#[doc = "to <code>[NonZero]\\<[u32]></code>."]
#[inline]
fn try_from(value: NonZero<i16>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u32>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i16>> for NonZero<u64> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i16]></code> "]
#[doc = "to <code>[NonZero]\\<[u64]></code>."]
#[inline]
fn try_from(value: NonZero<i16>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u64>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i16>> for NonZero<u128> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i16]></code> "]
#[doc = "to <code>[NonZero]\\<[u128]></code>."]
#[inline]
fn try_from(value: NonZero<i16>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u128>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
722#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i32>> for NonZero<u8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i32]></code> "]
#[doc = "to <code>[NonZero]\\<[u8]></code>."]
#[inline]
fn try_from(value: NonZero<i32>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u8>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i32>> for NonZero<u16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i32]></code> "]
#[doc = "to <code>[NonZero]\\<[u16]></code>."]
#[inline]
fn try_from(value: NonZero<i32>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u16>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i32>> for NonZero<u32> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i32]></code> "]
#[doc = "to <code>[NonZero]\\<[u32]></code>."]
#[inline]
fn try_from(value: NonZero<i32>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u32>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i32>> for NonZero<u64> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i32]></code> "]
#[doc = "to <code>[NonZero]\\<[u64]></code>."]
#[inline]
fn try_from(value: NonZero<i32>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u64>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i32>> for NonZero<u128> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i32]></code> "]
#[doc = "to <code>[NonZero]\\<[u128]></code>."]
#[inline]
fn try_from(value: NonZero<i32>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u128>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
723#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i64>> for NonZero<u8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i64]></code> "]
#[doc = "to <code>[NonZero]\\<[u8]></code>."]
#[inline]
fn try_from(value: NonZero<i64>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u8>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i64>> for NonZero<u16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i64]></code> "]
#[doc = "to <code>[NonZero]\\<[u16]></code>."]
#[inline]
fn try_from(value: NonZero<i64>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u16>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i64>> for NonZero<u32> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i64]></code> "]
#[doc = "to <code>[NonZero]\\<[u32]></code>."]
#[inline]
fn try_from(value: NonZero<i64>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u32>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i64>> for NonZero<u64> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i64]></code> "]
#[doc = "to <code>[NonZero]\\<[u64]></code>."]
#[inline]
fn try_from(value: NonZero<i64>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u64>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i64>> for NonZero<u128> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i64]></code> "]
#[doc = "to <code>[NonZero]\\<[u128]></code>."]
#[inline]
fn try_from(value: NonZero<i64>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u128>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
724#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i128>> for NonZero<u8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i128]></code> "]
#[doc = "to <code>[NonZero]\\<[u8]></code>."]
#[inline]
fn try_from(value: NonZero<i128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u8>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i128>> for NonZero<u16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i128]></code> "]
#[doc = "to <code>[NonZero]\\<[u16]></code>."]
#[inline]
fn try_from(value: NonZero<i128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u16>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i128>> for NonZero<u32> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i128]></code> "]
#[doc = "to <code>[NonZero]\\<[u32]></code>."]
#[inline]
fn try_from(value: NonZero<i128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u32>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i128>> for NonZero<u64> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i128]></code> "]
#[doc = "to <code>[NonZero]\\<[u64]></code>."]
#[inline]
fn try_from(value: NonZero<i128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u64>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<i128>> for NonZero<u128> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[i128]></code> "]
#[doc = "to <code>[NonZero]\\<[u128]></code>."]
#[inline]
fn try_from(value: NonZero<i128>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u128>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
725#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<isize>> for NonZero<u8> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[isize]></code> "]
#[doc = "to <code>[NonZero]\\<[u8]></code>."]
#[inline]
fn try_from(value: NonZero<isize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u8>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<isize>> for NonZero<u16> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[isize]></code> "]
#[doc = "to <code>[NonZero]\\<[u16]></code>."]
#[inline]
fn try_from(value: NonZero<isize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u16>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<isize>> for NonZero<u32> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[isize]></code> "]
#[doc = "to <code>[NonZero]\\<[u32]></code>."]
#[inline]
fn try_from(value: NonZero<isize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u32>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<isize>> for NonZero<u64> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[isize]></code> "]
#[doc = "to <code>[NonZero]\\<[u64]></code>."]
#[inline]
fn try_from(value: NonZero<isize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u64>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl TryFrom<NonZero<isize>> for NonZero<u128> {
type Error = TryFromIntError;
#[doc = "Attempts to convert <code>[NonZero]\\<[isize]></code> "]
#[doc = "to <code>[NonZero]\\<[u128]></code>."]
#[inline]
fn try_from(value: NonZero<isize>) -> Result<Self, Self::Error> {
Ok(unsafe { Self::new_unchecked(<u128>::try_from(value.get())?) })
}
}
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl 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);
726
727#[unstable(feature = "integer_casts", issue = "157388")]
729#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
730pub impl(self) const trait BoundedCastFromInt<T>: Sized {
731 #[unstable(feature = "integer_casts", issue = "157388")]
733 fn wrapping_cast_from(value: T) -> Self;
734
735 #[unstable(feature = "integer_casts", issue = "157388")]
737 fn saturating_cast_from(value: T) -> Self;
738}
739
740#[unstable(feature = "integer_casts", issue = "157388")]
742#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
743pub impl(self) const trait CheckedCastFromInt<T>: Sized {
744 #[unstable(feature = "integer_casts", issue = "157388")]
746 fn checked_cast_from(value: T) -> Option<Self>;
747
748 #[unstable(feature = "integer_casts", issue = "157388")]
755 unsafe fn unchecked_cast_from(value: T) -> Self;
756
757 #[unstable(feature = "integer_casts", issue = "157388")]
763 fn strict_cast_from(value: T) -> Self;
764}
765
766macro_rules! impl_int_cast {
767 ($Src:ty as [$($Dst:ty),*]) => {$(
768 #[unstable(feature = "integer_casts", issue = "157388")]
769 #[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
770 const impl CheckedCastFromInt<$Src> for $Dst {
771 #[inline]
772 fn checked_cast_from(value: $Src) -> Option<Self> {
773 value.try_into().ok()
774 }
775
776 #[inline(always)]
777 unsafe fn unchecked_cast_from(value: $Src) -> Self {
778 unsafe { value.try_into().unwrap_unchecked() }
780 }
781
782 #[inline]
783 #[track_caller]
784 fn strict_cast_from(value: $Src) -> Self {
785 match value.try_into() {
786 Ok(x) => x,
787 Err(_) => core::num::imp::overflow_panic::cast_integer()
788 }
789 }
790 }
791
792 #[unstable(feature = "integer_casts", issue = "157388")]
793 #[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
794 const impl BoundedCastFromInt<$Src> for $Dst {
795 #[inline(always)]
796 fn wrapping_cast_from(value: $Src) -> Self {
797 value as Self
798 }
799
800 #[inline]
801 #[allow(unused_comparisons)]
802 #[allow(irrefutable_let_patterns)]
803 fn saturating_cast_from(value: $Src) -> Self {
804 if let Ok(x) = value.try_into() {
805 return x;
806 }
807
808 if value < 0 { <$Dst>::MIN } else { <$Dst>::MAX }
809 }
810 }
811 )*};
812}
813
814macro_rules! impl_all_int_casts {
815 ([$($Src:ty),*]) => {$(
816 impl_int_cast!($Src as [u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize]);
817 )*};
818}
819
820#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u8> for u8 {
#[inline]
fn checked_cast_from(value: u8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u8> for u8 {
#[inline(always)]
fn wrapping_cast_from(value: u8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u8>::MIN } else { <u8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u8> for u16 {
#[inline]
fn checked_cast_from(value: u8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u8> for u16 {
#[inline(always)]
fn wrapping_cast_from(value: u8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u16>::MIN } else { <u16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u8> for u32 {
#[inline]
fn checked_cast_from(value: u8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u8> for u32 {
#[inline(always)]
fn wrapping_cast_from(value: u8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u32>::MIN } else { <u32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u8> for u64 {
#[inline]
fn checked_cast_from(value: u8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u8> for u64 {
#[inline(always)]
fn wrapping_cast_from(value: u8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u64>::MIN } else { <u64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u8> for u128 {
#[inline]
fn checked_cast_from(value: u8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u8> for u128 {
#[inline(always)]
fn wrapping_cast_from(value: u8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u128>::MIN } else { <u128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u8> for usize {
#[inline]
fn checked_cast_from(value: u8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u8> for usize {
#[inline(always)]
fn wrapping_cast_from(value: u8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <usize>::MIN } else { <usize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u8> for i8 {
#[inline]
fn checked_cast_from(value: u8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u8> for i8 {
#[inline(always)]
fn wrapping_cast_from(value: u8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i8>::MIN } else { <i8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u8> for i16 {
#[inline]
fn checked_cast_from(value: u8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u8> for i16 {
#[inline(always)]
fn wrapping_cast_from(value: u8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i16>::MIN } else { <i16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u8> for i32 {
#[inline]
fn checked_cast_from(value: u8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u8> for i32 {
#[inline(always)]
fn wrapping_cast_from(value: u8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i32>::MIN } else { <i32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u8> for i64 {
#[inline]
fn checked_cast_from(value: u8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u8> for i64 {
#[inline(always)]
fn wrapping_cast_from(value: u8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i64>::MIN } else { <i64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u8> for i128 {
#[inline]
fn checked_cast_from(value: u8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u8> for i128 {
#[inline(always)]
fn wrapping_cast_from(value: u8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i128>::MIN } else { <i128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u8> for isize {
#[inline]
fn checked_cast_from(value: u8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u8> for isize {
#[inline(always)]
fn wrapping_cast_from(value: u8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <isize>::MIN } else { <isize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u16> for u8 {
#[inline]
fn checked_cast_from(value: u16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u16> for u8 {
#[inline(always)]
fn wrapping_cast_from(value: u16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u8>::MIN } else { <u8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u16> for u16 {
#[inline]
fn checked_cast_from(value: u16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u16> for u16 {
#[inline(always)]
fn wrapping_cast_from(value: u16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u16>::MIN } else { <u16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u16> for u32 {
#[inline]
fn checked_cast_from(value: u16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u16> for u32 {
#[inline(always)]
fn wrapping_cast_from(value: u16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u32>::MIN } else { <u32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u16> for u64 {
#[inline]
fn checked_cast_from(value: u16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u16> for u64 {
#[inline(always)]
fn wrapping_cast_from(value: u16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u64>::MIN } else { <u64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u16> for u128 {
#[inline]
fn checked_cast_from(value: u16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u16> for u128 {
#[inline(always)]
fn wrapping_cast_from(value: u16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u128>::MIN } else { <u128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u16> for usize {
#[inline]
fn checked_cast_from(value: u16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u16> for usize {
#[inline(always)]
fn wrapping_cast_from(value: u16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <usize>::MIN } else { <usize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u16> for i8 {
#[inline]
fn checked_cast_from(value: u16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u16> for i8 {
#[inline(always)]
fn wrapping_cast_from(value: u16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i8>::MIN } else { <i8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u16> for i16 {
#[inline]
fn checked_cast_from(value: u16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u16> for i16 {
#[inline(always)]
fn wrapping_cast_from(value: u16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i16>::MIN } else { <i16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u16> for i32 {
#[inline]
fn checked_cast_from(value: u16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u16> for i32 {
#[inline(always)]
fn wrapping_cast_from(value: u16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i32>::MIN } else { <i32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u16> for i64 {
#[inline]
fn checked_cast_from(value: u16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u16> for i64 {
#[inline(always)]
fn wrapping_cast_from(value: u16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i64>::MIN } else { <i64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u16> for i128 {
#[inline]
fn checked_cast_from(value: u16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u16> for i128 {
#[inline(always)]
fn wrapping_cast_from(value: u16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i128>::MIN } else { <i128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u16> for isize {
#[inline]
fn checked_cast_from(value: u16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u16> for isize {
#[inline(always)]
fn wrapping_cast_from(value: u16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <isize>::MIN } else { <isize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u32> for u8 {
#[inline]
fn checked_cast_from(value: u32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u32> for u8 {
#[inline(always)]
fn wrapping_cast_from(value: u32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u8>::MIN } else { <u8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u32> for u16 {
#[inline]
fn checked_cast_from(value: u32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u32> for u16 {
#[inline(always)]
fn wrapping_cast_from(value: u32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u16>::MIN } else { <u16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u32> for u32 {
#[inline]
fn checked_cast_from(value: u32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u32> for u32 {
#[inline(always)]
fn wrapping_cast_from(value: u32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u32>::MIN } else { <u32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u32> for u64 {
#[inline]
fn checked_cast_from(value: u32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u32> for u64 {
#[inline(always)]
fn wrapping_cast_from(value: u32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u64>::MIN } else { <u64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u32> for u128 {
#[inline]
fn checked_cast_from(value: u32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u32> for u128 {
#[inline(always)]
fn wrapping_cast_from(value: u32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u128>::MIN } else { <u128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u32> for usize {
#[inline]
fn checked_cast_from(value: u32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u32> for usize {
#[inline(always)]
fn wrapping_cast_from(value: u32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <usize>::MIN } else { <usize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u32> for i8 {
#[inline]
fn checked_cast_from(value: u32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u32> for i8 {
#[inline(always)]
fn wrapping_cast_from(value: u32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i8>::MIN } else { <i8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u32> for i16 {
#[inline]
fn checked_cast_from(value: u32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u32> for i16 {
#[inline(always)]
fn wrapping_cast_from(value: u32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i16>::MIN } else { <i16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u32> for i32 {
#[inline]
fn checked_cast_from(value: u32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u32> for i32 {
#[inline(always)]
fn wrapping_cast_from(value: u32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i32>::MIN } else { <i32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u32> for i64 {
#[inline]
fn checked_cast_from(value: u32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u32> for i64 {
#[inline(always)]
fn wrapping_cast_from(value: u32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i64>::MIN } else { <i64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u32> for i128 {
#[inline]
fn checked_cast_from(value: u32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u32> for i128 {
#[inline(always)]
fn wrapping_cast_from(value: u32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i128>::MIN } else { <i128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u32> for isize {
#[inline]
fn checked_cast_from(value: u32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u32> for isize {
#[inline(always)]
fn wrapping_cast_from(value: u32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <isize>::MIN } else { <isize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u64> for u8 {
#[inline]
fn checked_cast_from(value: u64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u64> for u8 {
#[inline(always)]
fn wrapping_cast_from(value: u64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u8>::MIN } else { <u8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u64> for u16 {
#[inline]
fn checked_cast_from(value: u64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u64> for u16 {
#[inline(always)]
fn wrapping_cast_from(value: u64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u16>::MIN } else { <u16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u64> for u32 {
#[inline]
fn checked_cast_from(value: u64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u64> for u32 {
#[inline(always)]
fn wrapping_cast_from(value: u64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u32>::MIN } else { <u32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u64> for u64 {
#[inline]
fn checked_cast_from(value: u64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u64> for u64 {
#[inline(always)]
fn wrapping_cast_from(value: u64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u64>::MIN } else { <u64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u64> for u128 {
#[inline]
fn checked_cast_from(value: u64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u64> for u128 {
#[inline(always)]
fn wrapping_cast_from(value: u64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u128>::MIN } else { <u128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u64> for usize {
#[inline]
fn checked_cast_from(value: u64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u64> for usize {
#[inline(always)]
fn wrapping_cast_from(value: u64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <usize>::MIN } else { <usize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u64> for i8 {
#[inline]
fn checked_cast_from(value: u64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u64> for i8 {
#[inline(always)]
fn wrapping_cast_from(value: u64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i8>::MIN } else { <i8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u64> for i16 {
#[inline]
fn checked_cast_from(value: u64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u64> for i16 {
#[inline(always)]
fn wrapping_cast_from(value: u64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i16>::MIN } else { <i16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u64> for i32 {
#[inline]
fn checked_cast_from(value: u64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u64> for i32 {
#[inline(always)]
fn wrapping_cast_from(value: u64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i32>::MIN } else { <i32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u64> for i64 {
#[inline]
fn checked_cast_from(value: u64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u64> for i64 {
#[inline(always)]
fn wrapping_cast_from(value: u64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i64>::MIN } else { <i64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u64> for i128 {
#[inline]
fn checked_cast_from(value: u64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u64> for i128 {
#[inline(always)]
fn wrapping_cast_from(value: u64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i128>::MIN } else { <i128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u64> for isize {
#[inline]
fn checked_cast_from(value: u64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: u64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u64> for isize {
#[inline(always)]
fn wrapping_cast_from(value: u64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <isize>::MIN } else { <isize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u128> for u8 {
#[inline]
fn checked_cast_from(value: u128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: u128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u128> for u8 {
#[inline(always)]
fn wrapping_cast_from(value: u128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u8>::MIN } else { <u8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u128> for u16 {
#[inline]
fn checked_cast_from(value: u128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: u128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u128> for u16 {
#[inline(always)]
fn wrapping_cast_from(value: u128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u16>::MIN } else { <u16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u128> for u32 {
#[inline]
fn checked_cast_from(value: u128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: u128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u128> for u32 {
#[inline(always)]
fn wrapping_cast_from(value: u128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u32>::MIN } else { <u32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u128> for u64 {
#[inline]
fn checked_cast_from(value: u128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: u128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u128> for u64 {
#[inline(always)]
fn wrapping_cast_from(value: u128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u64>::MIN } else { <u64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u128> for u128 {
#[inline]
fn checked_cast_from(value: u128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: u128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u128> for u128 {
#[inline(always)]
fn wrapping_cast_from(value: u128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u128>::MIN } else { <u128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u128> for usize {
#[inline]
fn checked_cast_from(value: u128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: u128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u128> for usize {
#[inline(always)]
fn wrapping_cast_from(value: u128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <usize>::MIN } else { <usize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u128> for i8 {
#[inline]
fn checked_cast_from(value: u128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: u128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u128> for i8 {
#[inline(always)]
fn wrapping_cast_from(value: u128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i8>::MIN } else { <i8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u128> for i16 {
#[inline]
fn checked_cast_from(value: u128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: u128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u128> for i16 {
#[inline(always)]
fn wrapping_cast_from(value: u128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i16>::MIN } else { <i16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u128> for i32 {
#[inline]
fn checked_cast_from(value: u128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: u128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u128> for i32 {
#[inline(always)]
fn wrapping_cast_from(value: u128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i32>::MIN } else { <i32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u128> for i64 {
#[inline]
fn checked_cast_from(value: u128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: u128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u128> for i64 {
#[inline(always)]
fn wrapping_cast_from(value: u128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i64>::MIN } else { <i64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u128> for i128 {
#[inline]
fn checked_cast_from(value: u128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: u128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u128> for i128 {
#[inline(always)]
fn wrapping_cast_from(value: u128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i128>::MIN } else { <i128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<u128> for isize {
#[inline]
fn checked_cast_from(value: u128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: u128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: u128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<u128> for isize {
#[inline(always)]
fn wrapping_cast_from(value: u128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: u128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <isize>::MIN } else { <isize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<usize> for u8 {
#[inline]
fn checked_cast_from(value: usize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: usize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: usize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<usize> for u8 {
#[inline(always)]
fn wrapping_cast_from(value: usize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: usize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u8>::MIN } else { <u8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<usize> for u16 {
#[inline]
fn checked_cast_from(value: usize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: usize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: usize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<usize> for u16 {
#[inline(always)]
fn wrapping_cast_from(value: usize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: usize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u16>::MIN } else { <u16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<usize> for u32 {
#[inline]
fn checked_cast_from(value: usize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: usize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: usize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<usize> for u32 {
#[inline(always)]
fn wrapping_cast_from(value: usize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: usize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u32>::MIN } else { <u32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<usize> for u64 {
#[inline]
fn checked_cast_from(value: usize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: usize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: usize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<usize> for u64 {
#[inline(always)]
fn wrapping_cast_from(value: usize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: usize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u64>::MIN } else { <u64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<usize> for u128 {
#[inline]
fn checked_cast_from(value: usize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: usize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: usize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<usize> for u128 {
#[inline(always)]
fn wrapping_cast_from(value: usize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: usize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u128>::MIN } else { <u128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<usize> for usize {
#[inline]
fn checked_cast_from(value: usize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: usize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: usize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<usize> for usize {
#[inline(always)]
fn wrapping_cast_from(value: usize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: usize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <usize>::MIN } else { <usize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<usize> for i8 {
#[inline]
fn checked_cast_from(value: usize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: usize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: usize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<usize> for i8 {
#[inline(always)]
fn wrapping_cast_from(value: usize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: usize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i8>::MIN } else { <i8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<usize> for i16 {
#[inline]
fn checked_cast_from(value: usize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: usize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: usize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<usize> for i16 {
#[inline(always)]
fn wrapping_cast_from(value: usize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: usize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i16>::MIN } else { <i16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<usize> for i32 {
#[inline]
fn checked_cast_from(value: usize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: usize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: usize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<usize> for i32 {
#[inline(always)]
fn wrapping_cast_from(value: usize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: usize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i32>::MIN } else { <i32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<usize> for i64 {
#[inline]
fn checked_cast_from(value: usize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: usize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: usize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<usize> for i64 {
#[inline(always)]
fn wrapping_cast_from(value: usize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: usize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i64>::MIN } else { <i64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<usize> for i128 {
#[inline]
fn checked_cast_from(value: usize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: usize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: usize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<usize> for i128 {
#[inline(always)]
fn wrapping_cast_from(value: usize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: usize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i128>::MIN } else { <i128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<usize> for isize {
#[inline]
fn checked_cast_from(value: usize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: usize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: usize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<usize> for isize {
#[inline(always)]
fn wrapping_cast_from(value: usize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: usize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <isize>::MIN } else { <isize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i8> for u8 {
#[inline]
fn checked_cast_from(value: i8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i8> for u8 {
#[inline(always)]
fn wrapping_cast_from(value: i8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u8>::MIN } else { <u8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i8> for u16 {
#[inline]
fn checked_cast_from(value: i8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i8> for u16 {
#[inline(always)]
fn wrapping_cast_from(value: i8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u16>::MIN } else { <u16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i8> for u32 {
#[inline]
fn checked_cast_from(value: i8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i8> for u32 {
#[inline(always)]
fn wrapping_cast_from(value: i8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u32>::MIN } else { <u32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i8> for u64 {
#[inline]
fn checked_cast_from(value: i8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i8> for u64 {
#[inline(always)]
fn wrapping_cast_from(value: i8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u64>::MIN } else { <u64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i8> for u128 {
#[inline]
fn checked_cast_from(value: i8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i8> for u128 {
#[inline(always)]
fn wrapping_cast_from(value: i8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u128>::MIN } else { <u128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i8> for usize {
#[inline]
fn checked_cast_from(value: i8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i8> for usize {
#[inline(always)]
fn wrapping_cast_from(value: i8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <usize>::MIN } else { <usize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i8> for i8 {
#[inline]
fn checked_cast_from(value: i8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i8> for i8 {
#[inline(always)]
fn wrapping_cast_from(value: i8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i8>::MIN } else { <i8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i8> for i16 {
#[inline]
fn checked_cast_from(value: i8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i8> for i16 {
#[inline(always)]
fn wrapping_cast_from(value: i8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i16>::MIN } else { <i16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i8> for i32 {
#[inline]
fn checked_cast_from(value: i8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i8> for i32 {
#[inline(always)]
fn wrapping_cast_from(value: i8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i32>::MIN } else { <i32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i8> for i64 {
#[inline]
fn checked_cast_from(value: i8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i8> for i64 {
#[inline(always)]
fn wrapping_cast_from(value: i8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i64>::MIN } else { <i64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i8> for i128 {
#[inline]
fn checked_cast_from(value: i8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i8> for i128 {
#[inline(always)]
fn wrapping_cast_from(value: i8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i128>::MIN } else { <i128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i8> for isize {
#[inline]
fn checked_cast_from(value: i8) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i8) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i8) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i8> for isize {
#[inline(always)]
fn wrapping_cast_from(value: i8) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i8) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <isize>::MIN } else { <isize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i16> for u8 {
#[inline]
fn checked_cast_from(value: i16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i16> for u8 {
#[inline(always)]
fn wrapping_cast_from(value: i16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u8>::MIN } else { <u8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i16> for u16 {
#[inline]
fn checked_cast_from(value: i16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i16> for u16 {
#[inline(always)]
fn wrapping_cast_from(value: i16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u16>::MIN } else { <u16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i16> for u32 {
#[inline]
fn checked_cast_from(value: i16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i16> for u32 {
#[inline(always)]
fn wrapping_cast_from(value: i16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u32>::MIN } else { <u32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i16> for u64 {
#[inline]
fn checked_cast_from(value: i16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i16> for u64 {
#[inline(always)]
fn wrapping_cast_from(value: i16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u64>::MIN } else { <u64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i16> for u128 {
#[inline]
fn checked_cast_from(value: i16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i16> for u128 {
#[inline(always)]
fn wrapping_cast_from(value: i16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u128>::MIN } else { <u128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i16> for usize {
#[inline]
fn checked_cast_from(value: i16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i16> for usize {
#[inline(always)]
fn wrapping_cast_from(value: i16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <usize>::MIN } else { <usize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i16> for i8 {
#[inline]
fn checked_cast_from(value: i16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i16> for i8 {
#[inline(always)]
fn wrapping_cast_from(value: i16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i8>::MIN } else { <i8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i16> for i16 {
#[inline]
fn checked_cast_from(value: i16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i16> for i16 {
#[inline(always)]
fn wrapping_cast_from(value: i16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i16>::MIN } else { <i16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i16> for i32 {
#[inline]
fn checked_cast_from(value: i16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i16> for i32 {
#[inline(always)]
fn wrapping_cast_from(value: i16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i32>::MIN } else { <i32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i16> for i64 {
#[inline]
fn checked_cast_from(value: i16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i16> for i64 {
#[inline(always)]
fn wrapping_cast_from(value: i16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i64>::MIN } else { <i64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i16> for i128 {
#[inline]
fn checked_cast_from(value: i16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i16> for i128 {
#[inline(always)]
fn wrapping_cast_from(value: i16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i128>::MIN } else { <i128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i16> for isize {
#[inline]
fn checked_cast_from(value: i16) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i16) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i16) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i16> for isize {
#[inline(always)]
fn wrapping_cast_from(value: i16) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i16) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <isize>::MIN } else { <isize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i32> for u8 {
#[inline]
fn checked_cast_from(value: i32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i32> for u8 {
#[inline(always)]
fn wrapping_cast_from(value: i32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u8>::MIN } else { <u8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i32> for u16 {
#[inline]
fn checked_cast_from(value: i32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i32> for u16 {
#[inline(always)]
fn wrapping_cast_from(value: i32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u16>::MIN } else { <u16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i32> for u32 {
#[inline]
fn checked_cast_from(value: i32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i32> for u32 {
#[inline(always)]
fn wrapping_cast_from(value: i32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u32>::MIN } else { <u32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i32> for u64 {
#[inline]
fn checked_cast_from(value: i32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i32> for u64 {
#[inline(always)]
fn wrapping_cast_from(value: i32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u64>::MIN } else { <u64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i32> for u128 {
#[inline]
fn checked_cast_from(value: i32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i32> for u128 {
#[inline(always)]
fn wrapping_cast_from(value: i32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u128>::MIN } else { <u128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i32> for usize {
#[inline]
fn checked_cast_from(value: i32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i32> for usize {
#[inline(always)]
fn wrapping_cast_from(value: i32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <usize>::MIN } else { <usize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i32> for i8 {
#[inline]
fn checked_cast_from(value: i32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i32> for i8 {
#[inline(always)]
fn wrapping_cast_from(value: i32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i8>::MIN } else { <i8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i32> for i16 {
#[inline]
fn checked_cast_from(value: i32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i32> for i16 {
#[inline(always)]
fn wrapping_cast_from(value: i32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i16>::MIN } else { <i16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i32> for i32 {
#[inline]
fn checked_cast_from(value: i32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i32> for i32 {
#[inline(always)]
fn wrapping_cast_from(value: i32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i32>::MIN } else { <i32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i32> for i64 {
#[inline]
fn checked_cast_from(value: i32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i32> for i64 {
#[inline(always)]
fn wrapping_cast_from(value: i32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i64>::MIN } else { <i64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i32> for i128 {
#[inline]
fn checked_cast_from(value: i32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i32> for i128 {
#[inline(always)]
fn wrapping_cast_from(value: i32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i128>::MIN } else { <i128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i32> for isize {
#[inline]
fn checked_cast_from(value: i32) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i32) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i32) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i32> for isize {
#[inline(always)]
fn wrapping_cast_from(value: i32) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i32) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <isize>::MIN } else { <isize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i64> for u8 {
#[inline]
fn checked_cast_from(value: i64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i64> for u8 {
#[inline(always)]
fn wrapping_cast_from(value: i64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u8>::MIN } else { <u8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i64> for u16 {
#[inline]
fn checked_cast_from(value: i64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i64> for u16 {
#[inline(always)]
fn wrapping_cast_from(value: i64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u16>::MIN } else { <u16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i64> for u32 {
#[inline]
fn checked_cast_from(value: i64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i64> for u32 {
#[inline(always)]
fn wrapping_cast_from(value: i64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u32>::MIN } else { <u32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i64> for u64 {
#[inline]
fn checked_cast_from(value: i64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i64> for u64 {
#[inline(always)]
fn wrapping_cast_from(value: i64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u64>::MIN } else { <u64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i64> for u128 {
#[inline]
fn checked_cast_from(value: i64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i64> for u128 {
#[inline(always)]
fn wrapping_cast_from(value: i64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u128>::MIN } else { <u128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i64> for usize {
#[inline]
fn checked_cast_from(value: i64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i64> for usize {
#[inline(always)]
fn wrapping_cast_from(value: i64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <usize>::MIN } else { <usize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i64> for i8 {
#[inline]
fn checked_cast_from(value: i64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i64> for i8 {
#[inline(always)]
fn wrapping_cast_from(value: i64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i8>::MIN } else { <i8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i64> for i16 {
#[inline]
fn checked_cast_from(value: i64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i64> for i16 {
#[inline(always)]
fn wrapping_cast_from(value: i64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i16>::MIN } else { <i16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i64> for i32 {
#[inline]
fn checked_cast_from(value: i64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i64> for i32 {
#[inline(always)]
fn wrapping_cast_from(value: i64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i32>::MIN } else { <i32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i64> for i64 {
#[inline]
fn checked_cast_from(value: i64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i64> for i64 {
#[inline(always)]
fn wrapping_cast_from(value: i64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i64>::MIN } else { <i64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i64> for i128 {
#[inline]
fn checked_cast_from(value: i64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i64> for i128 {
#[inline(always)]
fn wrapping_cast_from(value: i64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i128>::MIN } else { <i128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i64> for isize {
#[inline]
fn checked_cast_from(value: i64) -> Option<Self> { value.try_into().ok() }
#[inline(always)]
unsafe fn unchecked_cast_from(value: i64) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i64) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i64> for isize {
#[inline(always)]
fn wrapping_cast_from(value: i64) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i64) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <isize>::MIN } else { <isize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i128> for u8 {
#[inline]
fn checked_cast_from(value: i128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: i128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i128> for u8 {
#[inline(always)]
fn wrapping_cast_from(value: i128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u8>::MIN } else { <u8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i128> for u16 {
#[inline]
fn checked_cast_from(value: i128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: i128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i128> for u16 {
#[inline(always)]
fn wrapping_cast_from(value: i128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u16>::MIN } else { <u16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i128> for u32 {
#[inline]
fn checked_cast_from(value: i128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: i128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i128> for u32 {
#[inline(always)]
fn wrapping_cast_from(value: i128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u32>::MIN } else { <u32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i128> for u64 {
#[inline]
fn checked_cast_from(value: i128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: i128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i128> for u64 {
#[inline(always)]
fn wrapping_cast_from(value: i128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u64>::MIN } else { <u64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i128> for u128 {
#[inline]
fn checked_cast_from(value: i128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: i128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i128> for u128 {
#[inline(always)]
fn wrapping_cast_from(value: i128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u128>::MIN } else { <u128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i128> for usize {
#[inline]
fn checked_cast_from(value: i128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: i128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i128> for usize {
#[inline(always)]
fn wrapping_cast_from(value: i128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <usize>::MIN } else { <usize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i128> for i8 {
#[inline]
fn checked_cast_from(value: i128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: i128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i128> for i8 {
#[inline(always)]
fn wrapping_cast_from(value: i128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i8>::MIN } else { <i8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i128> for i16 {
#[inline]
fn checked_cast_from(value: i128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: i128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i128> for i16 {
#[inline(always)]
fn wrapping_cast_from(value: i128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i16>::MIN } else { <i16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i128> for i32 {
#[inline]
fn checked_cast_from(value: i128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: i128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i128> for i32 {
#[inline(always)]
fn wrapping_cast_from(value: i128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i32>::MIN } else { <i32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i128> for i64 {
#[inline]
fn checked_cast_from(value: i128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: i128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i128> for i64 {
#[inline(always)]
fn wrapping_cast_from(value: i128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i64>::MIN } else { <i64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i128> for i128 {
#[inline]
fn checked_cast_from(value: i128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: i128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i128> for i128 {
#[inline(always)]
fn wrapping_cast_from(value: i128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i128>::MIN } else { <i128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<i128> for isize {
#[inline]
fn checked_cast_from(value: i128) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: i128) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: i128) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<i128> for isize {
#[inline(always)]
fn wrapping_cast_from(value: i128) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: i128) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <isize>::MIN } else { <isize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<isize> for u8 {
#[inline]
fn checked_cast_from(value: isize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: isize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: isize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<isize> for u8 {
#[inline(always)]
fn wrapping_cast_from(value: isize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: isize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u8>::MIN } else { <u8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<isize> for u16 {
#[inline]
fn checked_cast_from(value: isize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: isize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: isize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<isize> for u16 {
#[inline(always)]
fn wrapping_cast_from(value: isize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: isize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u16>::MIN } else { <u16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<isize> for u32 {
#[inline]
fn checked_cast_from(value: isize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: isize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: isize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<isize> for u32 {
#[inline(always)]
fn wrapping_cast_from(value: isize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: isize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u32>::MIN } else { <u32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<isize> for u64 {
#[inline]
fn checked_cast_from(value: isize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: isize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: isize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<isize> for u64 {
#[inline(always)]
fn wrapping_cast_from(value: isize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: isize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u64>::MIN } else { <u64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<isize> for u128 {
#[inline]
fn checked_cast_from(value: isize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: isize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: isize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<isize> for u128 {
#[inline(always)]
fn wrapping_cast_from(value: isize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: isize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <u128>::MIN } else { <u128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<isize> for usize {
#[inline]
fn checked_cast_from(value: isize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: isize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: isize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<isize> for usize {
#[inline(always)]
fn wrapping_cast_from(value: isize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: isize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <usize>::MIN } else { <usize>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<isize> for i8 {
#[inline]
fn checked_cast_from(value: isize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: isize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: isize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<isize> for i8 {
#[inline(always)]
fn wrapping_cast_from(value: isize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: isize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i8>::MIN } else { <i8>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<isize> for i16 {
#[inline]
fn checked_cast_from(value: isize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: isize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: isize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<isize> for i16 {
#[inline(always)]
fn wrapping_cast_from(value: isize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: isize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i16>::MIN } else { <i16>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<isize> for i32 {
#[inline]
fn checked_cast_from(value: isize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: isize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: isize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<isize> for i32 {
#[inline(always)]
fn wrapping_cast_from(value: isize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: isize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i32>::MIN } else { <i32>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<isize> for i64 {
#[inline]
fn checked_cast_from(value: isize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: isize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: isize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<isize> for i64 {
#[inline(always)]
fn wrapping_cast_from(value: isize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: isize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i64>::MIN } else { <i64>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<isize> for i128 {
#[inline]
fn checked_cast_from(value: isize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: isize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: isize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<isize> for i128 {
#[inline(always)]
fn wrapping_cast_from(value: isize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: isize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <i128>::MIN } else { <i128>::MAX }
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl CheckedCastFromInt<isize> for isize {
#[inline]
fn checked_cast_from(value: isize) -> Option<Self> {
value.try_into().ok()
}
#[inline(always)]
unsafe fn unchecked_cast_from(value: isize) -> Self {
unsafe { value.try_into().unwrap_unchecked() }
}
#[inline]
#[track_caller]
fn strict_cast_from(value: isize) -> Self {
match value.try_into() {
Ok(x) => x,
Err(_) => core::num::imp::overflow_panic::cast_integer(),
}
}
}
#[unstable(feature = "integer_casts", issue = "157388")]
#[rustc_const_unstable(feature = "integer_casts", issue = "157388")]
const impl BoundedCastFromInt<isize> for isize {
#[inline(always)]
fn wrapping_cast_from(value: isize) -> Self { value as Self }
#[inline]
#[allow(unused_comparisons)]
#[allow(irrefutable_let_patterns)]
fn saturating_cast_from(value: isize) -> Self {
if let Ok(x) = value.try_into() { return x; }
if value < 0 { <isize>::MIN } else { <isize>::MAX }
}
}impl_all_int_casts!([u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize]);