NonNullMut

Struct NonNullMut 

Source
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>

Source

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>

Source

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!();
}
Source

pub const unsafe fn new_unchecked(ptr: *mut T) -> Self

Like NonNull::new_unchecked

§Safety

See NonNull::new_unchecked for safety concerns and examples.

Source

pub const fn from_inner(inner: NonNull<T>) -> Self

Source

pub fn addr(self) -> NonZeroUsize

Source

pub fn with_addr(self, addr: NonZeroUsize) -> Self

Source

pub fn map_addr(self, f: impl FnOnce(NonZeroUsize) -> NonZeroUsize) -> Self

Source

pub const fn as_ptr(self) -> *mut T

Source

pub const fn as_inner(self) -> NonNull<T>

Get inner NonNull<T>

Source

pub const unsafe fn as_ref<'a>(&self) -> &'a T

Like NonNull::as_ref

§Safety

See NonNull::as_ref for safety concerns and examples.

Source

pub const unsafe fn as_mut<'a>(&mut self) -> &'a mut T

Like NonNull::as_mut

§Safety

See NonNull::as_mut for safety concerns and examples.

Source

pub const fn cast<U>(self) -> NonNull<U>

Source

pub const unsafe fn offset(self, count: isize) -> Self
where T: Sized,

Like NonNull::offset

§Safety

See NonNull::offset for safety concerns and examples.

Source

pub const unsafe fn byte_offset(self, count: isize) -> Self

Like NonNull::byte_offset

§Safety

See NonNull::byte_offset for safety concerns and examples.

Source

pub const unsafe fn add(self, count: usize) -> Self
where T: Sized,

Like NonNull::add

§Safety

See NonNull::add for safety concerns and examples.

Source

pub const unsafe fn byte_add(self, count: usize) -> Self

Like NonNull::byte_add

§Safety

See NonNull::byte_add for safety concerns and examples.

Source

pub const unsafe fn sub(self, count: usize) -> Self
where T: Sized,

Like NonNull::sub

§Safety

See NonNull::sub for safety concerns and examples.

Source

pub const unsafe fn byte_sub(self, count: usize) -> Self

Like NonNull::byte_sub

§Safety

See NonNull::byte_sub for safety concerns and examples.

Source

pub const unsafe fn offset_from(self, origin: NonNull<T>) -> isize
where T: Sized,

Like NonNull::offset_from

§Safety

See NonNull::offset_from for safety concerns and examples.

Source

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.

Source

pub const unsafe fn read(self) -> T
where T: Sized,

Like NonNull::read

§Safety

See NonNull::read for safety concerns and examples.

Source

pub unsafe fn read_volatile(self) -> T
where T: Sized,

Like NonNull::read_volatile

§Safety

See NonNull::read_volatile for safety concerns and examples.

Source

pub const unsafe fn read_unaligned(self) -> T
where T: Sized,

Like NonNull::read_unaligned

§Safety

See NonNull::read_unaligned for safety concerns and examples.

Source

pub const unsafe fn copy_to(self, dest: NonNull<T>, count: usize)
where T: Sized,

Like NonNull::copy_to

§Safety

See NonNull::copy_to for safety concerns and examples.

Source

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.

Source

pub const unsafe fn copy_from(self, src: NonNull<T>, count: usize)
where T: Sized,

Like NonNull::copy_from

§Safety

See NonNull::copy_from for safety concerns and examples.

Source

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.

Source

pub unsafe fn drop_in_place(self)

Like NonNull::drop_in_place

§Safety

See NonNull::drop_in_place for safety concerns and examples.

Source

pub const unsafe fn write(self, val: T)
where T: Sized,

Like NonNull::write

§Safety

See NonNull::write for safety concerns and examples.

Source

pub const unsafe fn write_bytes(self, val: u8, count: usize)
where T: Sized,

Like NonNull::write_bytes

§Safety

See NonNull::write_bytes for safety concerns and examples.

Source

pub unsafe fn write_volatile(self, val: T)
where T: Sized,

Like NonNull::write_volatile

§Safety

See NonNull::write_volatile for safety concerns and examples.

Source

pub const unsafe fn write_unaligned(self, val: T)
where T: Sized,

Like NonNull::write_unaligned

§Safety

See NonNull::write_unaligned for safety concerns and examples.

Source

pub unsafe fn replace(self, src: T) -> T
where T: Sized,

Like NonNull::replace

§Safety

See NonNull::replace for safety concerns and examples.

Source

pub const unsafe fn swap(self, with: NonNull<T>)
where T: Sized,

Like NonNull::swap

§Safety

See NonNull::swap for safety concerns and examples.

Source

pub fn align_offset(self, align: usize) -> usize
where T: Sized,

Source

pub fn is_aligned(self) -> bool
where T: Sized,

Source§

impl<T> NonNullMut<[T]>

Source

pub const fn slice_from_raw_parts(data: NonNull<T>, len: usize) -> Self

Source

pub const fn len(self) -> usize

Source

pub const fn is_empty(self) -> bool

Trait Implementations§

Source§

impl<T: ?Sized> Clone for NonNullMut<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: ?Sized> Debug for NonNullMut<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ?Sized> From<&T> for NonNullMut<T>

Source§

fn from(r: &T) -> Self

Converts to this type from the input type.
Source§

impl<T: ?Sized> From<&mut T> for NonNullMut<T>

Source§

fn from(r: &mut T) -> Self

Converts to this type from the input type.
Source§

impl<T: ?Sized> From<NonNull<T>> for NonNullMut<T>

Source§

fn from(inner: NonNull<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: ?Sized> From<NonNullMut<T>> for NonNull<T>

Source§

fn from(value: NonNullMut<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: ?Sized> Hash for NonNullMut<T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: ?Sized> Ord for NonNullMut<T>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: ?Sized> PartialEq for NonNullMut<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: ?Sized> PartialOrd for NonNullMut<T>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: ?Sized> Pointer for NonNullMut<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ?Sized> Copy for NonNullMut<T>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.