Stop using deprecated NonZero APIs
These will eventually be removed (though the NonZero<T> lang item will likely stay).
This commit is contained in:
parent
22f7a02958
commit
6d682c9adc
1 changed files with 18 additions and 10 deletions
|
|
@ -2341,17 +2341,21 @@ impl<T: ?Sized> Unique<T> {
|
|||
///
|
||||
/// `ptr` must be non-null.
|
||||
pub const unsafe fn new_unchecked(ptr: *mut T) -> Self {
|
||||
Unique { pointer: NonZero::new_unchecked(ptr), _marker: PhantomData }
|
||||
Unique { pointer: NonZero(ptr as _), _marker: PhantomData }
|
||||
}
|
||||
|
||||
/// Creates a new `Unique` if `ptr` is non-null.
|
||||
pub fn new(ptr: *mut T) -> Option<Self> {
|
||||
NonZero::new(ptr as *const T).map(|nz| Unique { pointer: nz, _marker: PhantomData })
|
||||
if !ptr.is_null() {
|
||||
Some(Unique { pointer: NonZero(ptr as _), _marker: PhantomData })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Acquires the underlying `*mut` pointer.
|
||||
pub fn as_ptr(self) -> *mut T {
|
||||
self.pointer.get() as *mut T
|
||||
self.pointer.0 as *mut T
|
||||
}
|
||||
|
||||
/// Dereferences the content.
|
||||
|
|
@ -2397,7 +2401,7 @@ impl<T: ?Sized> fmt::Pointer for Unique<T> {
|
|||
#[allow(deprecated)]
|
||||
impl<'a, T: ?Sized> From<&'a mut T> for Unique<T> {
|
||||
fn from(reference: &'a mut T) -> Self {
|
||||
Unique { pointer: NonZero::from(reference), _marker: PhantomData }
|
||||
Unique { pointer: NonZero(reference as _), _marker: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2405,7 +2409,7 @@ impl<'a, T: ?Sized> From<&'a mut T> for Unique<T> {
|
|||
#[allow(deprecated)]
|
||||
impl<'a, T: ?Sized> From<&'a T> for Unique<T> {
|
||||
fn from(reference: &'a T) -> Self {
|
||||
Unique { pointer: NonZero::from(reference), _marker: PhantomData }
|
||||
Unique { pointer: NonZero(reference as _), _marker: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2476,19 +2480,23 @@ impl<T: ?Sized> NonNull<T> {
|
|||
/// `ptr` must be non-null.
|
||||
#[stable(feature = "nonnull", since = "1.25.0")]
|
||||
pub const unsafe fn new_unchecked(ptr: *mut T) -> Self {
|
||||
NonNull { pointer: NonZero::new_unchecked(ptr) }
|
||||
NonNull { pointer: NonZero(ptr as _) }
|
||||
}
|
||||
|
||||
/// Creates a new `NonNull` if `ptr` is non-null.
|
||||
#[stable(feature = "nonnull", since = "1.25.0")]
|
||||
pub fn new(ptr: *mut T) -> Option<Self> {
|
||||
NonZero::new(ptr as *const T).map(|nz| NonNull { pointer: nz })
|
||||
if !ptr.is_null() {
|
||||
Some(NonNull { pointer: NonZero(ptr as _) })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Acquires the underlying `*mut` pointer.
|
||||
#[stable(feature = "nonnull", since = "1.25.0")]
|
||||
pub fn as_ptr(self) -> *mut T {
|
||||
self.pointer.get() as *mut T
|
||||
self.pointer.0 as *mut T
|
||||
}
|
||||
|
||||
/// Dereferences the content.
|
||||
|
|
@ -2589,7 +2597,7 @@ impl<T: ?Sized> From<Unique<T>> for NonNull<T> {
|
|||
#[allow(deprecated)]
|
||||
impl<'a, T: ?Sized> From<&'a mut T> for NonNull<T> {
|
||||
fn from(reference: &'a mut T) -> Self {
|
||||
NonNull { pointer: NonZero::from(reference) }
|
||||
NonNull { pointer: NonZero(reference as _) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2597,6 +2605,6 @@ impl<'a, T: ?Sized> From<&'a mut T> for NonNull<T> {
|
|||
#[allow(deprecated)]
|
||||
impl<'a, T: ?Sized> From<&'a T> for NonNull<T> {
|
||||
fn from(reference: &'a T) -> Self {
|
||||
NonNull { pointer: NonZero::from(reference) }
|
||||
NonNull { pointer: NonZero(reference as _) }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue