Skip to content

Commit 052ed24

Browse files
committed
Implement From<&NonZero<T>> for &T
1 parent bfe809d commit 052ed24

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

library/core/src/num/nonzero.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,18 @@ where
287287
}
288288
}
289289

290+
impl<T> From<&NonZero<T>> for &T
291+
where
292+
T: ZeroablePrimitive,
293+
{
294+
#[inline]
295+
fn from(nonzero: &NonZero<T>) -> Self {
296+
// SAFETY: `ZeroablePrimitive` guarantees that the size and bit
297+
// validity of `.0` is such that this transmute is sound.
298+
unsafe { intrinsics::transmute_unchecked(nonzero) }
299+
}
300+
}
301+
290302
#[stable(feature = "nonzero_bitor", since = "1.45.0")]
291303
impl<T> BitOr for NonZero<T>
292304
where

0 commit comments

Comments
 (0)