IntoBuf

Trait IntoBuf 

Source
pub trait IntoBuf {
    type Buf: Buf;

    // Required method
    fn into_buf(self) -> Self::Buf;
}
Expand description

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.

§Examples

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);

Required Associated Types§

Source

type Buf: Buf

The Buf type that self is being converted into

Required Methods§

Source

fn into_buf(self) -> Self::Buf

Creates a Buf from a value.

§Examples
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);

Implementations on Foreign Types§

Source§

impl IntoBuf for i8

Source§

type Buf = Option<[u8; 1]>

Source§

fn into_buf(self) -> <i8 as IntoBuf>::Buf

Source§

impl IntoBuf for u8

Source§

type Buf = Option<[u8; 1]>

Source§

fn into_buf(self) -> <u8 as IntoBuf>::Buf

Source§

impl IntoBuf for String

Source§

impl IntoBuf for Vec<u8>

Source§

impl<'a> IntoBuf for &'a &'static str

Source§

type Buf = Cursor<&'static [u8]>

Source§

fn into_buf(self) -> <&'a &'static str as IntoBuf>::Buf

Source§

impl<'a> IntoBuf for &'a &'static [u8]

Source§

type Buf = Cursor<&'static [u8]>

Source§

fn into_buf(self) -> <&'a &'static [u8] as IntoBuf>::Buf

Source§

impl<'a> IntoBuf for &'a str

Source§

type Buf = Cursor<&'a [u8]>

Source§

fn into_buf(self) -> <&'a str as IntoBuf>::Buf

Source§

impl<'a> IntoBuf for &'a String

Source§

type Buf = Cursor<&'a [u8]>

Source§

fn into_buf(self) -> <&'a String as IntoBuf>::Buf

Source§

impl<'a> IntoBuf for &'a Vec<u8>

Source§

type Buf = Cursor<&'a [u8]>

Source§

fn into_buf(self) -> <&'a Vec<u8> as IntoBuf>::Buf

Source§

impl<'a> IntoBuf for &'a [u8]

Source§

type Buf = Cursor<&'a [u8]>

Source§

fn into_buf(self) -> <&'a [u8] as IntoBuf>::Buf

Source§

impl<'a> IntoBuf for &'a mut [u8]

Source§

type Buf = Cursor<&'a mut [u8]>

Source§

fn into_buf(self) -> <&'a mut [u8] as IntoBuf>::Buf

Implementors§