Struct NonNullRef

Source
#[repr(transparent)]
pub struct NonNullRef<T>(pub NonNull<T>);

Tuple Fields§

§0: NonNull<T>

Implementations§

Source§

impl<T> NonNullRef<T>

Source

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

Source

pub fn cast<U>(self: NonNullRef<T>) -> NonNullRef<U>

Methods from Deref<Target = NonNull<T>>§

1.25.0 · Source

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

Returns a shared reference to the value. If the value may be uninitialized, as_uninit_ref must be used instead.

For the mutable counterpart see as_mut.

§Safety

When calling this method, you have to ensure that the pointer is convertible to a reference.

§Examples
use std::ptr::NonNull;

let mut x = 0u32;
let ptr = NonNull::new(&mut x as *mut _).expect("ptr is null!");

let ref_x = unsafe { ptr.as_ref() };
println!("{ref_x}");

Trait Implementations§

Source§

impl<__> Clone for NonNullRef<__>

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> Debug for NonNullRef<T>

Source§

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

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

impl<T> Deref for NonNullRef<T>

Source§

type Target = NonNull<T>

The resulting type after dereferencing.
Source§

fn deref(self: &NonNullRef<T>) -> &NonNull<T>

Dereferences the value.
Source§

impl<'lt, T: 'lt> From<&'lt T> for NonNullRef<T>

Source§

fn from(it: &'lt T) -> NonNullRef<T>

Converts to this type from the input type.
Source§

impl<'lt, T: 'lt> From<&'lt mut T> for NonNullRef<T>

Source§

fn from(it: &'lt mut T) -> NonNullRef<T>

Converts to this type from the input type.
Source§

impl<T> From<NonNull<T>> for NonNullRef<T>

Source§

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

Converts to this type from the input type.
Source§

impl<T: ReprC> ReprC for NonNullRef<T>

Source§

type CLayout = *const <T as ReprC>::CLayout

The CType having the same layout as Self.
Source§

fn is_valid(it: &*const T::CLayout) -> bool

Sanity checks that can be performed on an instance of the CType layout. Read more
Source§

impl<__> Copy for NonNullRef<__>

Auto Trait Implementations§

§

impl<T> Freeze for NonNullRef<T>

§

impl<T> RefUnwindSafe for NonNullRef<T>
where T: RefUnwindSafe,

§

impl<T> !Send for NonNullRef<T>

§

impl<T> !Sync for NonNullRef<T>

§

impl<T> Unpin for NonNullRef<T>

§

impl<T> UnwindSafe for NonNullRef<T>
where T: RefUnwindSafe,

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> AsOut<T> for T
where T: Copy,

Source§

fn as_out<'out>(&'out mut self) -> Out<'out, T>

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> CompatExt for T

Source§

fn compat(self) -> Compat<T>

Applies the Compat adapter by value. Read more
Source§

fn compat_ref(&self) -> Compat<&T>

Applies the Compat adapter by shared reference. Read more
Source§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the Compat adapter by mutable reference. Read more
Source§

impl<T> ConcreteReprC for T
where T: ReprC + ?Sized, <T as ReprC>::CLayout: CType<OPAQUE_KIND = Concrete>,

Source§

impl<T> FitForCBox for T

Source§

type CBoxWrapped = Box_<T>

Available on crate feature alloc only.
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> ManuallyDropMut for T

Source§

type Ret = ManuallyDrop<T>

Source§

fn manually_drop_mut<'__>(&'__ mut self) -> &'__ mut ManuallyDrop<T>

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> UpcastAny for T
where T: 'static,

Source§

fn upcast_any(&self) -> &(dyn Any + 'static)

Available on crate feature headers only.
Source§

impl<F> ZeroSizedElseWrathOfTheGඞds for F