[][src]Enum ben::Encoder

pub enum Encoder {
    Int(i64),
    Bytes(Vec<u8>),
    List(Vec<Self>),
    Dict(BTreeMap<&'static str, Self>),
}

Encoder to use for encoding data into bencode format.

Variants

Int(i64)
Bytes(Vec<u8>)
List(Vec<Self>)
Dict(BTreeMap<&'static str, Self>)

Methods

impl Encoder[src]

pub fn to_vec(&self) -> Vec<u8>[src]

Encodes data into a vector of bencoded bytes.

Examples:

Basic usage:

use ben::Encoder;

let enc = Encoder::from(vec![Encoder::from("Hello"), Encoder::from("World")]);
let bytes = enc.to_vec();
assert_eq!(b"l5:Hello5:Worlde", &bytes[..]);

pub fn write<W: Write>(&self, w: &mut W) -> Result<()>[src]

Encodes and writes the data into given Write object.

Examples:

Basic usage:

use ben::Encoder;

let mut bytes = vec![];
let enc = Encoder::from(vec![Encoder::from("Hello"), Encoder::from("World")]);
enc.write(&mut bytes).unwrap();
assert_eq!(b"l5:Hello5:Worlde", &bytes[..]);

Trait Implementations

impl Clone for Encoder[src]

impl Debug for Encoder[src]

impl<'_> From<&'_ [u8]> for Encoder[src]

impl<'_> From<&'_ str> for Encoder[src]

impl From<BTreeMap<&'static str, Encoder>> for Encoder[src]

impl From<String> for Encoder[src]

impl From<Vec<Encoder>> for Encoder[src]

impl From<Vec<u8>> for Encoder[src]

impl From<i64> for Encoder[src]

impl PartialEq<Encoder> for Encoder[src]

impl PartialOrd<Encoder> for Encoder[src]

impl StructuralPartialEq for Encoder[src]

Auto Trait Implementations

impl RefUnwindSafe for Encoder

impl Send for Encoder

impl Sync for Encoder

impl Unpin for Encoder

impl UnwindSafe for Encoder

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.