Make Unique
s methods const
This commit is contained in:
parent
b9a37ad0d9
commit
34eaf52829
2 changed files with 4 additions and 3 deletions
|
@ -124,6 +124,7 @@
|
||||||
#![feature(const_option)]
|
#![feature(const_option)]
|
||||||
#![feature(const_pin)]
|
#![feature(const_pin)]
|
||||||
#![feature(const_replace)]
|
#![feature(const_replace)]
|
||||||
|
#![feature(const_ptr_is_null)]
|
||||||
#![feature(const_ptr_offset)]
|
#![feature(const_ptr_offset)]
|
||||||
#![feature(const_ptr_offset_from)]
|
#![feature(const_ptr_offset_from)]
|
||||||
#![feature(const_ptr_read)]
|
#![feature(const_ptr_read)]
|
||||||
|
|
|
@ -92,7 +92,7 @@ impl<T: ?Sized> Unique<T> {
|
||||||
|
|
||||||
/// Creates a new `Unique` if `ptr` is non-null.
|
/// Creates a new `Unique` if `ptr` is non-null.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(ptr: *mut T) -> Option<Self> {
|
pub const fn new(ptr: *mut T) -> Option<Self> {
|
||||||
if !ptr.is_null() {
|
if !ptr.is_null() {
|
||||||
// SAFETY: The pointer has already been checked and is not null.
|
// SAFETY: The pointer has already been checked and is not null.
|
||||||
Some(unsafe { Unique { pointer: ptr as _, _marker: PhantomData } })
|
Some(unsafe { Unique { pointer: ptr as _, _marker: PhantomData } })
|
||||||
|
@ -115,7 +115,7 @@ impl<T: ?Sized> Unique<T> {
|
||||||
/// (unbound) lifetime is needed, use `&*my_ptr.as_ptr()`.
|
/// (unbound) lifetime is needed, use `&*my_ptr.as_ptr()`.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn as_ref(&self) -> &T {
|
pub const unsafe fn as_ref(&self) -> &T {
|
||||||
// SAFETY: the caller must guarantee that `self` meets all the
|
// SAFETY: the caller must guarantee that `self` meets all the
|
||||||
// requirements for a reference.
|
// requirements for a reference.
|
||||||
unsafe { &*self.as_ptr() }
|
unsafe { &*self.as_ptr() }
|
||||||
|
@ -128,7 +128,7 @@ impl<T: ?Sized> Unique<T> {
|
||||||
/// (unbound) lifetime is needed, use `&mut *my_ptr.as_ptr()`.
|
/// (unbound) lifetime is needed, use `&mut *my_ptr.as_ptr()`.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn as_mut(&mut self) -> &mut T {
|
pub const unsafe fn as_mut(&mut self) -> &mut T {
|
||||||
// SAFETY: the caller must guarantee that `self` meets all the
|
// SAFETY: the caller must guarantee that `self` meets all the
|
||||||
// requirements for a mutable reference.
|
// requirements for a mutable reference.
|
||||||
unsafe { &mut *self.as_ptr() }
|
unsafe { &mut *self.as_ptr() }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue