pub trait AlignedBuf: Buf {
// Provided methods
fn copy_to_aligned(
&mut self,
len: usize,
alignment: Alignment,
) -> ByteBuffer { ... }
fn copy_to_const_aligned<const A: usize>(
&mut self,
len: usize,
) -> ConstByteBuffer<A> { ... }
}
Expand description
An extension to the Buf
trait that provides a function copy_to_aligned
similar to
copy_to_bytes
that allows for zero-copy aligned reads where possible.
Provided Methods§
Sourcefn copy_to_aligned(&mut self, len: usize, alignment: Alignment) -> ByteBuffer
fn copy_to_aligned(&mut self, len: usize, alignment: Alignment) -> ByteBuffer
Copy the next len
bytes from the buffer into a new buffer with the given alignment.
This will be zero-copy wherever possible.
The Buf
trait has a specialized copy_to_bytes
function that allows the implementation
of Buf
for Bytes
and BytesMut
to return bytes with zero-copy.
This function provides similar functionality for ByteBuffer
.
TODO(ngates): what should this do the alignment of the current buffer? We have to advance it by len..
Sourcefn copy_to_const_aligned<const A: usize>(
&mut self,
len: usize,
) -> ConstByteBuffer<A>
fn copy_to_const_aligned<const A: usize>( &mut self, len: usize, ) -> ConstByteBuffer<A>
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.