Module layout

Module layout 

Source
Expand description

The different layouts used by ArcSlice and ArcSliceMut.

A layout defines how the data is stored, impacting memory size and the behavior of some operations like clone.

Almost all layouts are compatible with each other: ArcSlice::with_layout and ArcSliceMut::with_layout allows to update the layout used, often at zero cost. See FromLayout.

ArcSlice and ArcSliceMut have a default layout, which can be overridden using crate features.

§Which layout to choose

The default layout, ArcLayout, should support most of the use cases efficiently. The other layouts are designed to support some particular buffers without allocating an inner Arc:

Since layout primarily affects ArcSlice/ArcSliceMut instantiation, libraries generally don’t need to worry about it: they can either accept the default layout or use a generic one in public APIs, and expose the most appropriate layout in their return types. Libraries should not override the default layout using [crate features], as it would impact every other crates.
Binaries should use the default layout, adapting it to the use case using [crate features].

In any case, layout choice is primarily a performance concern and should be supported by measurement.

§Layouts summary

LayoutArcSlice sizestatic/empty slices supportarbitrary buffers supportcloning may allocateoptimized for
ArcLayout3 * size_of::<usize>()yes (optional)yes (optional)noregular ArcSlice
BoxedSliceLayout3 * size_of::<usize>()yesyesyesBox<[T]>
VecLayout4 * size_of::<usize>()yesyesyesVec<T>
RawLayout4 * size_of::<usize>()yesyesnoRawBuffer

Structs§

ArcLayout
The default and most optimized layout.
BoxedSliceLayout
Enables storing a boxed slice into an ArcSlice without requiring the allocation of an inner Arc, as long as there is a single instance.
RawLayoutraw-buffer
Enables storing a RawBuffer, without requiring the allocation of an inner Arc.
VecLayout
Enables storing a vector into an ArcSlice without requiring the allocation of an inner Arc, as long as there is a single instance.

Traits§

AnyBufferLayout
A layout that supports arbitrary buffers, such as Vec, shared memory regions, ffi buffers, etc.
CloneNoAllocLayout
A layout that supports clone without allocating.
FromLayout
A layout that can be converted from another one.
Layout
A layout, which defines how ArcSlice data is stored.
LayoutMut
A layout, which defines how ArcSliceMut data is stored.
StaticLayout
A layout that supports static slices without inner Arc allocation.
TruncateNoAllocLayout
A layout that supports truncate without allocating.

Type Aliases§

DefaultLayout
Default layout used by ArcSlice.
DefaultLayoutMut
Default layout used by ArcSliceMut.