Trait gvariant::aligned_bytes::AsAligned
source · [−]pub trait AsAligned<A: Alignment> {
fn as_aligned(&self) -> &AlignedSlice<A>;
}
Expand description
Allows narrowing the alignment of a &AlignedSlice
This can be convenient to accept any AlignedSlice
with sufficient
alignment as an argument to a function. For example:
fn foo(data : &impl AsAligned<A2>) {
let data = data.as_aligned();
or if a function requires a specific alignment you can do:
bar(data.as_aligned());
Mostly we convert from AlignedSlice<A8>
-> AlignedSlice<A4>
->
AlignedSlice<A2>
-> AlignedSlice<A1>
, but this can also be used to go
from &[u8]
to AlignedSlice<A1>
.
This is intended as a 0 overhead abstraction. In release mode this should compile down to nothing.