Skip to content

Commit 52c577b

Browse files
committed
Expose Unique::from<NonNull> in const internally
1 parent b1c4064 commit 52c577b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Diff for: core/src/ptr/unique.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ impl<T: ?Sized> Unique<T> {
100100
}
101101
}
102102

103+
/// Create a new `Unique` from a `NonNull` in const context.
104+
#[inline]
105+
pub const fn from_non_null(pointer: NonNull<T>) -> Self {
106+
Unique { pointer, _marker: PhantomData }
107+
}
108+
103109
/// Acquires the underlying `*mut` pointer.
104110
#[must_use = "`self` will be dropped if the result is not used"]
105111
#[inline]
@@ -202,6 +208,6 @@ impl<T: ?Sized> From<NonNull<T>> for Unique<T> {
202208
/// This conversion is infallible since `NonNull` cannot be null.
203209
#[inline]
204210
fn from(pointer: NonNull<T>) -> Self {
205-
Unique { pointer, _marker: PhantomData }
211+
Unique::from_non_null(pointer)
206212
}
207213
}

0 commit comments

Comments
 (0)