[][src]Trait bytes::IntoBuf

pub trait IntoBuf {
    type Buf: Buf;
    fn into_buf(self) -> Self::Buf;
}

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

Associated Types

type Buf: Buf

The Buf type that self is being converted into

Loading content...

Required methods

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);
Loading content...

Implementations on Foreign Types

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

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

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

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

impl<'a> IntoBuf for &'a str[src]

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

impl IntoBuf for Vec<u8>[src]

type Buf = Cursor<Vec<u8>>

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

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

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

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

impl<'a> IntoBuf for &'a &'static str[src]

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

impl IntoBuf for String[src]

type Buf = Cursor<Vec<u8>>

impl<'a> IntoBuf for &'a String[src]

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

impl IntoBuf for u8[src]

type Buf = Option<[u8; 1]>

impl IntoBuf for i8[src]

type Buf = Option<[u8; 1]>

Loading content...

Implementors

impl IntoBuf for Bytes[src]

type Buf = Cursor<Self>

impl IntoBuf for BytesMut[src]

type Buf = Cursor<Self>

impl<'a> IntoBuf for &'a Bytes[src]

type Buf = Cursor<Self>

impl<'a> IntoBuf for &'a BytesMut[src]

type Buf = Cursor<&'a BytesMut>

impl<T: Buf> IntoBuf for T[src]

type Buf = Self

Loading content...