FromLayout

Trait FromLayout 

Source
pub trait FromLayout<L: Layout>: Layout { }
Expand description

A layout that can be converted from another one.

As long as a layout implement AnyBufferLayout, every other layout can be converted to it. This conversion is often very cheap, when the default ArcSlice buffer is used, but it may require to allocate an Arc when to arbitrary buffers specially supported by the input layout. For example, converting ArcSlice<S, BoxedSliceLayout> to ArcSlice<S, ArcLayout<true>> might allocate an Arc if a boxed slice was store inlined.

ArcLayout<false> doesn’t implement AnyBufferLayout, so it cannot straightforwardly be converted from other layouts, as it may not support the underlying buffer. However, the actual underlying buffer may be compatible, for example, an ArcSlice<S, VecLayout> backed by an Arc buffer can in fact be converted to anArcSlice<S, ArcLayout<false>>. Fallible conversions like ArcSlice::try_with_layout/ArcSliceMut::try_freeze/etc. can be used to handle this edge case.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<L1: AnyBufferLayout, L2: AnyBufferLayout> FromLayout<L1> for L2

Source§

impl<const STATIC: bool, L: Layout> FromLayout<ArcLayout<false, STATIC>> for L