[][src]Trait abin::BinBuilder

pub trait BinBuilder<'a> {
    type T: AnyBin;
    fn push(&mut self, segment: impl Into<BinSegment<'a, Self::T>>);
fn build(&mut self) -> Self::T; fn push_bin(&mut self, bin: impl Into<Self::T>) { ... }
fn push_slice(&mut self, slice: impl Into<&'a [u8]>) { ... }
fn push_static(&mut self, slice: impl Into<&'static [u8]>) { ... }
fn push_given_vec(&mut self, vec: impl Into<Vec<u8>>) { ... }
fn push_u8(&mut self, byte: u8) { ... } }

Trait used to build a binary efficiently (with just one allocation & no re-allocation or even without allocation).

use abin::{NewBin, BinSegment, Bin, AnyBin, BinBuilder};

let mut builder = NewBin::builder();
builder.push(BinSegment::Static("Hello, ".as_bytes()));
builder.push(BinSegment::Static("World!".as_bytes()));
let bin : Bin = builder.build();

assert_eq!("Hello, World!".as_bytes(), bin.as_slice());

Associated Types

type T: AnyBin

Loading content...

Required methods

fn push(&mut self, segment: impl Into<BinSegment<'a, Self::T>>)

fn build(&mut self) -> Self::T

Builds the binary.

Note: After calling this method, the builder will be empty again and can be re-used. We use &mut self here instead of self to make sure the builder is not copied (it's large). I'm not sure how well rust would optimize self here.

Loading content...

Provided methods

fn push_bin(&mut self, bin: impl Into<Self::T>)

fn push_slice(&mut self, slice: impl Into<&'a [u8]>)

fn push_static(&mut self, slice: impl Into<&'static [u8]>)

fn push_given_vec(&mut self, vec: impl Into<Vec<u8>>)

fn push_u8(&mut self, byte: u8)

Loading content...

Implementors

Loading content...