Auto merge of #54240 - csmoe:nonzero_from, r=alexcrichton

Impl From<NonZero<T>> for T

Closes https://github.com/rust-lang/rust/issues/54171

r? @SimonSapin
This commit is contained in:
bors
2018-09-29 19:38:12 +00:00
2 changed files with 14 additions and 0 deletions
+7
View File
@@ -93,6 +93,13 @@ pub fn get(self) -> $Int {
}
#[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
}
+7
View File
@@ -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);
}