Skip to content

Commit 02deb4c

Browse files
committed
Add lossless conversion by reference for NonZero integers
1 parent 998914f commit 02deb4c

File tree

1 file changed

+10
-0
lines changed
  • library/core/src/convert

1 file changed

+10
-0
lines changed

library/core/src/convert/num.rs

+10
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ macro_rules! nzint_impl_from {
430430
}
431431
}
432432
}
433+
434+
impl_from_ref! { $Small, $Large }
433435
};
434436
($Small: ty, $Large: ty, #[$attr:meta]) => {
435437
nzint_impl_from!($Small,
@@ -444,31 +446,39 @@ macro_rules! nzint_impl_from {
444446
}
445447

446448
// Non-zero Unsigned -> Non-zero Unsigned
449+
impl_from_ref! { NonZeroU8, NonZeroU8 }
447450
nzint_impl_from! { NonZeroU8, NonZeroU16, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
448451
nzint_impl_from! { NonZeroU8, NonZeroU32, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
449452
nzint_impl_from! { NonZeroU8, NonZeroU64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
450453
nzint_impl_from! { NonZeroU8, NonZeroU128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
451454
nzint_impl_from! { NonZeroU8, NonZeroUsize, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
455+
impl_from_ref! { NonZeroU16, NonZeroU16 }
452456
nzint_impl_from! { NonZeroU16, NonZeroU32, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
453457
nzint_impl_from! { NonZeroU16, NonZeroU64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
454458
nzint_impl_from! { NonZeroU16, NonZeroU128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
455459
nzint_impl_from! { NonZeroU16, NonZeroUsize, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
460+
impl_from_ref! { NonZeroU32, NonZeroU32 }
456461
nzint_impl_from! { NonZeroU32, NonZeroU64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
457462
nzint_impl_from! { NonZeroU32, NonZeroU128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
463+
impl_from_ref! { NonZeroU64, NonZeroU64 }
458464
nzint_impl_from! { NonZeroU64, NonZeroU128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
459465

460466
// Non-zero Signed -> Non-zero Signed
467+
impl_from_ref! { NonZeroI8, NonZeroI8 }
461468
nzint_impl_from! { NonZeroI8, NonZeroI16, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
462469
nzint_impl_from! { NonZeroI8, NonZeroI32, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
463470
nzint_impl_from! { NonZeroI8, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
464471
nzint_impl_from! { NonZeroI8, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
465472
nzint_impl_from! { NonZeroI8, NonZeroIsize, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
473+
impl_from_ref! { NonZeroI16, NonZeroI16 }
466474
nzint_impl_from! { NonZeroI16, NonZeroI32, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
467475
nzint_impl_from! { NonZeroI16, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
468476
nzint_impl_from! { NonZeroI16, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
469477
nzint_impl_from! { NonZeroI16, NonZeroIsize, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
478+
impl_from_ref! { NonZeroI32, NonZeroI32 }
470479
nzint_impl_from! { NonZeroI32, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
471480
nzint_impl_from! { NonZeroI32, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
481+
impl_from_ref! { NonZeroI64, NonZeroI64 }
472482
nzint_impl_from! { NonZeroI64, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
473483

474484
// NonZero UnSigned -> Non-zero Signed

0 commit comments

Comments
 (0)