pub struct UninitView<'a, T: ?Sized> { /* private fields */ }
Expand description

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.

Implementations

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.

Split so that the second part fits the layout.

See Uninit::split_layout for more details.

Split so that the tail is aligned and valid for a U.

Split so that the tail is aligned for a slice [U].

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.

Split the uninit view at a byte boundary.

See Uninit::split_at_byte for more details.

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.

Try to cast to an UninitView for a slice type.

Split off the tail that is not required for holding an instance of T.

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.

Create a reference to typed uninitialized memory.

It is given a capacity of memory to which it refers in bytes.

Safety

The ptr must describe a valid, sized region. Refer to Layout::for_value_raw for details. This criteria is trivially fulfilled for any sized T.

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.

Return the number of bytes this may refer to.

Try to cast to an UninitView for another type.

Acquires the underlying *const T pointer.

Acquires the underlying pointer as a NonNull.

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.

Turn this into a reference to the content.

Safety

The caller must ensure that the content has already been initialized.

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.

Create an view on potentially uninitialized memory bytes of a slice of MaybeUninit.

Get the pointer to the first element of the slice.

Calculate the theoretical capacity of a slice in the pointed-to allocation.

Split the slice at an index.

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.

Split the first element from the slice.

Split the last element from the slice.

Turn this into a slice of standard MaybeUninits.

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.

Check if the view fits some layout.

The cast to a type of the provided layout will work without error.

Borrow another view of the Uninit region.

Get the byte size of the total allocation.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
The type we point to. This influences which kinds of unsizing are possible. Read more
The output type when unsizing the pointee to U.
Get the raw inner pointer.
Replace the container inner pointer with an unsized version. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Convert a pointer, as if with unsize coercion. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.