Conversion into a Buf
An IntoBuf
implementation defines how to convert a value into a Buf
.
This is common for types that represent byte storage of some kind. IntoBuf
may be implemented directly for types or on references for those types.
use bytes::{Buf, IntoBuf, BigEndian};
let bytes = b"\x00\x01hello world";
let mut buf = bytes.into_buf();
assert_eq!(1, buf.get_u16::<BigEndian>());
let mut rest = [0; 11];
buf.copy_to_slice(&mut rest);
assert_eq!(b"hello world", &rest);
The Buf
type that self
is being converted into
Creates a Buf
from a value.
use bytes::{Buf, IntoBuf, BigEndian};
let bytes = b"\x00\x01hello world";
let mut buf = bytes.into_buf();
assert_eq!(1, buf.get_u16::<BigEndian>());
let mut rest = [0; 11];
buf.copy_to_slice(&mut rest);
assert_eq!(b"hello world", &rest);
impl<T: Buf> IntoBuf for T type Buf = Self; | |