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:
BoxedSliceLayoutandVecLayoutare intended for boxed slice/vector buffers, and should be used only when clones are unlikely;RawLayoutshould be used withArcand other raw buffers.
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
| Layout | ArcSlice size | static/empty slices support | arbitrary buffers support | cloning may allocate | optimized for |
|---|---|---|---|---|---|
ArcLayout | 3 * size_of::<usize>() | yes (optional) | yes (optional) | no | regular ArcSlice |
BoxedSliceLayout | 3 * size_of::<usize>() | yes | yes | yes | Box<[T]> |
VecLayout | 4 * size_of::<usize>() | yes | yes | yes | Vec<T> |
RawLayout | 4 * size_of::<usize>() | yes | yes | no | RawBuffer |
Structs§
- ArcLayout
- The default and most optimized layout.
- Boxed
Slice Layout - Enables storing a boxed slice into an
ArcSlicewithout requiring the allocation of an inner Arc, as long as there is a single instance. - RawLayout
raw-buffer - Enables storing a
RawBuffer, without requiring the allocation of an inner Arc. - VecLayout
- Enables storing a vector into an
ArcSlicewithout requiring the allocation of an inner Arc, as long as there is a single instance.
Traits§
- AnyBuffer
Layout - A layout that supports arbitrary buffers, such as
Vec, shared memory regions, ffi buffers, etc. - Clone
NoAlloc Layout - A layout that supports
clonewithout allocating. - From
Layout - A layout that can be converted from another one.
- Layout
- A layout, which defines how
ArcSlicedata is stored. - Layout
Mut - A layout, which defines how
ArcSliceMutdata is stored. - Static
Layout - A layout that supports static slices without inner Arc allocation.
- Truncate
NoAlloc Layout - A layout that supports
truncatewithout allocating.
Type Aliases§
- Default
Layout - Default layout used by
ArcSlice. - Default
Layout Mut - Default layout used by
ArcSliceMut.