diff options
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/num/mod.rs | 7 | ||||
| -rw-r--r-- | src/libcore/tests/nonzero.rs | 7 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 12da0455cc5..c4b59738478 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -93,6 +93,13 @@ assert_eq!(size_of::<Option<std::num::", stringify!($Ty), ">>(), size_of::<", st } + #[stable(feature = "from_nonzero", since = "1.31.0")] + impl From<$Ty> for $Int { + fn from(nonzero: $Ty) -> Self { + nonzero.0 .0 + } + } + impl_nonzero_fmt! { (Debug, Display, Binary, Octal, LowerHex, UpperHex) for $Ty } diff --git a/src/libcore/tests/nonzero.rs b/src/libcore/tests/nonzero.rs index 8d39298bac3..bbb1ef76bcc 100644 --- a/src/libcore/tests/nonzero.rs +++ b/src/libcore/tests/nonzero.rs @@ -121,3 +121,10 @@ fn test_match_nonzero_const_pattern() { _ => panic!("Expected the const item as a pattern to match.") } } + +#[test] +fn test_from_nonzero() { + let nz = NonZeroU32::new(1).unwrap(); + let num: u32 = nz.into(); + assert_eq!(num, 1u32); +} |
