pub struct NonNullMut<T: ?Sized> { /* private fields */ }Expand description
NonNull<T>, but T is invariant like *mut T
Like NonNull<T>, but T is invariant like *mut T
§Examples
use nonnull_mut::NonNullMut;
assert_eq!(size_of::<NonNullMut<i16>>(), size_of::<Option<NonNullMut<i16>>>());
assert_eq!(align_of::<NonNullMut<i16>>(), align_of::<Option<NonNullMut<i16>>>());
assert_eq!(size_of::<NonNullMut<str>>(), size_of::<Option<NonNullMut<str>>>());
assert_eq!(align_of::<NonNullMut<str>>(), align_of::<Option<NonNullMut<str>>>());Implementations§
Source§impl<T> NonNullMut<T>
impl<T> NonNullMut<T>
Sourcepub const fn dangling() -> Self
pub const fn dangling() -> Self
Like NonNull::dangling
§Examples
use nonnull_mut::NonNullMut;
let ptr = NonNullMut::<u32>::dangling();
// Important: don't try to access the value of `ptr` without
// initializing it first! The pointer is not null but isn't valid either!Source§impl<T: ?Sized> NonNullMut<T>
impl<T: ?Sized> NonNullMut<T>
Sourcepub const fn new(ptr: *mut T) -> Option<Self>
pub const fn new(ptr: *mut T) -> Option<Self>
Like NonNull::new
§Examples
use nonnull_mut::NonNullMut;
let mut x = 0u32;
let ptr = NonNullMut::<u32>::new(&mut x as *mut _).expect("ptr is null!");
if let Some(ptr) = NonNullMut::<u32>::new(std::ptr::null_mut()) {
unreachable!();
}Sourcepub const unsafe fn new_unchecked(ptr: *mut T) -> Self
pub const unsafe fn new_unchecked(ptr: *mut T) -> Self
Sourcepub const fn from_inner(inner: NonNull<T>) -> Self
pub const fn from_inner(inner: NonNull<T>) -> Self
Create NonNullMut<T> from NonNull<T>
Sourcepub fn addr(self) -> NonZeroUsize
pub fn addr(self) -> NonZeroUsize
Like NonNull::addr
Sourcepub fn with_addr(self, addr: NonZeroUsize) -> Self
pub fn with_addr(self, addr: NonZeroUsize) -> Self
Like NonNull::with_addr
Sourcepub fn map_addr(self, f: impl FnOnce(NonZeroUsize) -> NonZeroUsize) -> Self
pub fn map_addr(self, f: impl FnOnce(NonZeroUsize) -> NonZeroUsize) -> Self
Like NonNull::map_addr
Sourcepub const fn as_ptr(self) -> *mut T
pub const fn as_ptr(self) -> *mut T
Like NonNull::as_ptr
Sourcepub const fn as_inner(self) -> NonNull<T>
pub const fn as_inner(self) -> NonNull<T>
Get inner NonNull<T>
Sourcepub const fn cast<U>(self) -> NonNull<U>
pub const fn cast<U>(self) -> NonNull<U>
Like NonNull::cast
Sourcepub const unsafe fn byte_offset(self, count: isize) -> Self
pub const unsafe fn byte_offset(self, count: isize) -> Self
Sourcepub const unsafe fn offset_from(self, origin: NonNull<T>) -> isizewhere
T: Sized,
pub const unsafe fn offset_from(self, origin: NonNull<T>) -> isizewhere
T: Sized,
Sourcepub const unsafe fn byte_offset_from<U: ?Sized>(
self,
origin: NonNull<U>,
) -> isize
pub const unsafe fn byte_offset_from<U: ?Sized>( self, origin: NonNull<U>, ) -> isize
Like NonNull::byte_offset_from
§Safety
See NonNull::byte_offset_from for safety concerns and examples.
Sourcepub unsafe fn read_volatile(self) -> Twhere
T: Sized,
pub unsafe fn read_volatile(self) -> Twhere
T: Sized,
Sourcepub const unsafe fn read_unaligned(self) -> Twhere
T: Sized,
pub const unsafe fn read_unaligned(self) -> Twhere
T: Sized,
Sourcepub const unsafe fn copy_to_nonoverlapping(self, dest: NonNull<T>, count: usize)where
T: Sized,
pub const unsafe fn copy_to_nonoverlapping(self, dest: NonNull<T>, count: usize)where
T: Sized,
Like NonNull::copy_to_nonoverlapping
§Safety
See NonNull::copy_to_nonoverlapping for safety concerns and examples.
Sourcepub const unsafe fn copy_from_nonoverlapping(
self,
src: NonNull<T>,
count: usize,
)where
T: Sized,
pub const unsafe fn copy_from_nonoverlapping(
self,
src: NonNull<T>,
count: usize,
)where
T: Sized,
Like NonNull::copy_from_nonoverlapping
§Safety
See NonNull::copy_from_nonoverlapping for safety concerns and examples.
Sourcepub unsafe fn drop_in_place(self)
pub unsafe fn drop_in_place(self)
Sourcepub const unsafe fn write_bytes(self, val: u8, count: usize)where
T: Sized,
pub const unsafe fn write_bytes(self, val: u8, count: usize)where
T: Sized,
Sourcepub unsafe fn write_volatile(self, val: T)where
T: Sized,
pub unsafe fn write_volatile(self, val: T)where
T: Sized,
Sourcepub const unsafe fn write_unaligned(self, val: T)where
T: Sized,
pub const unsafe fn write_unaligned(self, val: T)where
T: Sized,
§Safety
See NonNull::write_unaligned for safety concerns and examples.
Sourcepub fn align_offset(self, align: usize) -> usizewhere
T: Sized,
pub fn align_offset(self, align: usize) -> usizewhere
T: Sized,
Sourcepub fn is_aligned(self) -> boolwhere
T: Sized,
pub fn is_aligned(self) -> boolwhere
T: Sized,
Like NonNull::is_aligned
Source§impl<T> NonNullMut<[T]>
impl<T> NonNullMut<[T]>
Sourcepub const fn slice_from_raw_parts(data: NonNull<T>, len: usize) -> Self
pub const fn slice_from_raw_parts(data: NonNull<T>, len: usize) -> Self
Sourcepub const fn len(self) -> usize
pub const fn len(self) -> usize
Like NonNull::len
Sourcepub const fn is_empty(self) -> bool
pub const fn is_empty(self) -> bool
Like NonNull::is_empty
Trait Implementations§
Source§impl<T: ?Sized> Clone for NonNullMut<T>
impl<T: ?Sized> Clone for NonNullMut<T>
Source§impl<T: ?Sized> Debug for NonNullMut<T>
impl<T: ?Sized> Debug for NonNullMut<T>
Source§impl<T: ?Sized> From<NonNullMut<T>> for NonNull<T>
impl<T: ?Sized> From<NonNullMut<T>> for NonNull<T>
Source§fn from(value: NonNullMut<T>) -> Self
fn from(value: NonNullMut<T>) -> Self
Converts to this type from the input type.
Source§impl<T: ?Sized> Hash for NonNullMut<T>
impl<T: ?Sized> Hash for NonNullMut<T>
Source§impl<T: ?Sized> Ord for NonNullMut<T>
impl<T: ?Sized> Ord for NonNullMut<T>
Source§impl<T: ?Sized> PartialEq for NonNullMut<T>
impl<T: ?Sized> PartialEq for NonNullMut<T>
Source§impl<T: ?Sized> PartialOrd for NonNullMut<T>
impl<T: ?Sized> PartialOrd for NonNullMut<T>
Source§impl<T: ?Sized> Pointer for NonNullMut<T>
impl<T: ?Sized> Pointer for NonNullMut<T>
impl<T: ?Sized> Copy for NonNullMut<T>
impl<T: ?Sized> Eq for NonNullMut<T>
Auto Trait Implementations§
impl<T> Freeze for NonNullMut<T>where
T: ?Sized,
impl<T> RefUnwindSafe for NonNullMut<T>where
T: RefUnwindSafe + ?Sized,
impl<T> !Send for NonNullMut<T>
impl<T> !Sync for NonNullMut<T>
impl<T> Unpin for NonNullMut<T>where
T: ?Sized,
impl<T> UnwindSafe for NonNullMut<T>where
T: RefUnwindSafe + ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more