diff options
| author | James Wainwright <james.wainwright@lowrisc.org> | 2025-03-26 20:45:55 +0000 |
|---|---|---|
| committer | James Wainwright <james.wainwright@lowrisc.org> | 2025-03-26 20:46:07 +0000 |
| commit | d872845eae7f9988995fb8ca35f86d08de999409 (patch) | |
| tree | 1320ed68997dde4e072afcb0a0bbd2d4f4c0f96e | |
| parent | 19cab6b878ab18dce4816d85ac52b317214c485f (diff) | |
| download | rust-d872845eae7f9988995fb8ca35f86d08de999409.tar.gz rust-d872845eae7f9988995fb8ca35f86d08de999409.zip | |
Expose `Unique::from<NonNull>` in const internally
| -rw-r--r-- | library/core/src/ptr/unique.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/library/core/src/ptr/unique.rs b/library/core/src/ptr/unique.rs index 4810ebe01f9..d688ce2a07a 100644 --- a/library/core/src/ptr/unique.rs +++ b/library/core/src/ptr/unique.rs @@ -100,6 +100,12 @@ impl<T: ?Sized> Unique<T> { } } + /// Create a new `Unique` from a `NonNull` in const context. + #[inline] + pub const fn from_non_null(pointer: NonNull<T>) -> Self { + Unique { pointer, _marker: PhantomData } + } + /// Acquires the underlying `*mut` pointer. #[must_use = "`self` will be dropped if the result is not used"] #[inline] @@ -202,6 +208,6 @@ impl<T: ?Sized> From<NonNull<T>> for Unique<T> { /// This conversion is infallible since `NonNull` cannot be null. #[inline] fn from(pointer: NonNull<T>) -> Self { - Unique { pointer, _marker: PhantomData } + Unique::from_non_null(pointer) } } |
