Struct outref::Out

source ·
pub struct Out<'a, T: 'a + ?Sized> { /* private fields */ }
Expand description

Out reference (&'a out T).

An out reference is similar to a mutable reference, but it may point to uninitialized memory. An out reference may be used to initialize the pointee or represent a data buffer.

&'a out T can be converted from:

It is not allowed to corrupt or de-initialize the pointee, which may cause unsoundness. It is the main difference between &'a out T and &'a mut MaybeUninit<T> /&'a mut [MaybeUninit<T>].

Any reads through an out reference may read uninitialized value(s).

Implementations§

source§

impl<'a, T: ?Sized> Out<'a, T>

source

pub unsafe fn new(data: *mut T) -> Self

Forms an Out<'a, T>

§Safety
  • data must be valid for writes.
  • data must be properly aligned.
source

pub unsafe fn assume_init(self) -> &'a mut T

Converts to a mutable (unique) reference to the value.

§Safety

The referenced value must be initialized when calling this function.

source

pub fn reborrow<'s>(&'s mut self) -> Out<'s, T>
where 'a: 's,

Reborrows the out reference for a shorter lifetime.

source§

impl<'a, T> Out<'a, T>

source

pub fn from_mut(data: &'a mut T) -> Self
where T: Copy,

Forms an Out<'a, T>.

source

pub fn from_uninit(data: &'a mut MaybeUninit<T>) -> Self

Forms an Out<'a, T> from an uninitialized value.

source

pub unsafe fn into_uninit(self) -> &'a mut MaybeUninit<T>

Converts to &'a mut MaybeUninit<T>

§Safety

It is not allowed to corrupt or de-initialize the pointee.

source

pub fn as_mut_ptr(&mut self) -> *mut T

Returns an unsafe mutable pointer to the value.

source§

impl<'a, T> Out<'a, [T]>

source

pub fn from_slice(slice: &'a mut [T]) -> Self
where T: Copy,

Forms an Out<'a, [T]>.

source

pub fn from_uninit_slice(slice: &'a mut [MaybeUninit<T>]) -> Self

Forms an Out<'a, [T]> from an uninitialized slice.

source

pub unsafe fn into_uninit_slice(self) -> &'a mut [MaybeUninit<T>]

Converts to &'a mut [MaybeUninit<T>]

§Safety

It is not allowed to corrupt or de-initialize the pointee.

source

pub const fn is_empty(&self) -> bool

Returns true if the slice has a length of 0.

source

pub const fn len(&self) -> usize

Returns the number of elements in the slice.

source

pub fn as_mut_ptr(&mut self) -> *mut T

Returns an unsafe mutable pointer to the slice’s buffer.

Trait Implementations§

source§

impl<T: Send> Send for Out<'_, T>

source§

impl<T: Sync> Sync for Out<'_, T>

source§

impl<T: Unpin> Unpin for Out<'_, T>

Auto Trait Implementations§

§

impl<'a, T> Freeze for Out<'a, T>
where T: ?Sized,

§

impl<'a, T> RefUnwindSafe for Out<'a, T>
where T: RefUnwindSafe + ?Sized,

§

impl<'a, T> !UnwindSafe for Out<'a, T>

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

§

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

§

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.