[−][src]Struct static_alloc::uninit::UninitView
A non-mutable view on a region used in an Uninit
.
Makes it possible to utilize the traversal methods (split*
, cast*
, ..) without requiring a
mutable reference to the original Uninit
. It will also never expose mutable pointers or
accidentally offer an aliased mutable reference. Prefer this to instead avoiding the borrow of
the Uninit
and manually managing pointers to the region.
Methods
impl<'_> UninitView<'_, ()>
[src]
pub unsafe fn from_memory(ptr: NonNull<u8>, len: usize) -> Self
[src]
Create a uninit view from raw memory.
Safety
A valid allocation must exist at the pointer with length at least len
.
In particular, it is UB to create this from a reference to a variable of a type for
which a completely uninitialized content is not valid. The standard type for avoiding the
UB is core::mem::MaybeUninit
.
When in doubt, refactor code such that utilization of from_maybe_uninit
is possible.
pub fn split_layout(&mut self, layout: Layout) -> Option<Self>
[src]
Split so that the second part fits the layout.
See Uninit::split_layout
for more details.
impl<'a> UninitView<'a, ()>
[src]
pub fn split_cast<U>(&mut self) -> Option<UninitView<'a, U>>
[src]
Split so that the tail is aligned and valid for a U
.
pub fn split_slice<U>(&mut self) -> Option<UninitView<'a, [U]>>
[src]
Split so that the tail is aligned for a slice [U]
.
impl<'_, T> UninitView<'_, T>
[src]
pub fn invent_for_zst() -> Self
[src]
Invent a new uninit allocation for a zero-sized type (ZST).
Panics
This method panics when the type parameter is not a zero sized type.
impl<'a, T> UninitView<'a, T>
[src]
pub fn split_at_byte(&mut self, at: usize) -> Option<UninitView<'a, ()>>
[src]
Split the uninit view at a byte boundary.
See Uninit::split_at_byte
for more details.
pub fn from_maybe_uninit(mem: &'a MaybeUninit<T>) -> Self
[src]
Create an view to the inner bytes of a MaybeUninit
.
This is hardly useful on its own but since UninitView
mirrors the traversal methods of
Uninit
it can be used to get pointers to already initialized elements in an immutable
context.
pub fn cast<U>(self) -> Result<UninitView<'a, U>, Self>
[src]
Try to cast to an UninitView
for another type.
pub fn cast_slice<U>(self) -> Result<UninitView<'a, [U]>, Self>
[src]
Try to cast to an UninitView
for a slice type.
pub fn split_to_fit(&mut self) -> UninitView<'a, ()>
[src]
Split off the tail that is not required for holding an instance of T
.
pub const fn as_ptr(&self) -> *const T
[src]
Acquires the underlying *const T
pointer.
pub fn as_non_null(&self) -> NonNull<T>
[src]
Acquires the underlying pointer as a NonNull
.
pub unsafe fn as_ref(&self) -> &T
[src]
Dereferences the content.
The resulting lifetime is bound to self so this behaves "as if" it were actually an
instance of T that is getting borrowed. If a longer lifetime is needed, use into_ref
.
Safety
The caller must ensure that the content has already been initialized.
pub unsafe fn into_ref(self) -> &'a T
[src]
Turn this into a reference to the content.
Safety
The caller must ensure that the content has already been initialized.
pub fn into_maybe_uninit(self) -> &'a MaybeUninit<T>
[src]
Turn this into a reference to standard MaybeUninit
.
This is mainly useful for interfacing with other consumers which expect standard library
types and to mirror Uninit
.
Note that the sequence from_maybe_uninit
, into_maybe_uninit
is a no-op. The converse is
however not the case, as it will potentially discard unused padding present in the original
Uninit
.
impl<'a, T> UninitView<'a, [T]>
[src]
pub fn empty() -> Self
[src]
Creates a pointer to an empty slice.
Note that it will not be a mutable empty slice which means that it would be UB to
use it as an Uninit
.
pub fn from_maybe_uninit_slice(mem: &'a [MaybeUninit<T>]) -> Self
[src]
Create an view on potentially uninitialized memory bytes of a slice of MaybeUninit
.
pub fn as_begin_ptr(&self) -> *const T
[src]
Get the pointer to the first element of the slice.
pub fn capacity(&self) -> usize
[src]
Calculate the theoretical capacity of a slice in the pointed-to allocation.
pub fn split_at(&mut self, at: usize) -> Option<Self>
[src]
Split the slice at an index.
pub fn shrink_to_fit(&mut self) -> UninitView<'a, ()>
[src]
Get the trailing bytes behind the slice.
The underlying allocation need not be a multiple of the slice element size which may leave
unusable bytes. This splits these unusable bytes into an untyped Uninit
which can be
reused arbitrarily.
This operation is idempotent.
pub fn split_first(&mut self) -> Option<UninitView<'a, T>>
[src]
Split the first element from the slice.
pub fn split_last(&mut self) -> Option<UninitView<'a, T>>
[src]
Split the last element from the slice.
pub fn into_maybe_uninit_slice(self) -> &'a [MaybeUninit<T>]
[src]
Turn this into a slice of standard MaybeUninit
s.
This is mainly useful for interfacing with other consumers which expect standard library
types and to mirror Uninit
.
Note that the sequence from_maybe_uninit_slice
, into_maybe_uninit_slice
is a no-op. The
converse is however not the case, as it will potentially discard unused padding present in
the original Uninit
.
impl<'a, T: ?Sized> UninitView<'a, T>
[src]
pub fn fits(&self, layout: Layout) -> bool
[src]
Check if the view fits some layout.
The cast
to a type of the provided layout will work without error.
pub fn borrow(&self) -> UninitView<T>
[src]
Borrow another view of the Uninit
region.
pub const fn size(&self) -> usize
[src]
Get the byte size of the total allocation.
Trait Implementations
impl<'_, T: ?Sized> Debug for UninitView<'_, T>
[src]
impl<'_, T: ?Sized> Copy for UninitView<'_, T>
[src]
impl<'a, T> From<&'a MaybeUninit<T>> for UninitView<'a, T>
[src]
fn from(mem: &'a MaybeUninit<T>) -> Self
[src]
impl<'a, T> From<&'a [MaybeUninit<T>]> for UninitView<'a, [T]>
[src]
fn from(mem: &'a [MaybeUninit<T>]) -> Self
[src]
impl<'a, T> From<Uninit<'a, T>> for UninitView<'a, T>
[src]
impl<'_, T: ?Sized> Clone for UninitView<'_, T>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<'_, T> Default for UninitView<'_, [T]>
[src]
Auto Trait Implementations
impl<'a, T: ?Sized> Unpin for UninitView<'a, T>
impl<'a, T> !Send for UninitView<'a, T>
impl<'a, T> !Sync for UninitView<'a, T>
Blanket Implementations
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,