tokio-fmt-encoder

Crates.iotokio-fmt-encoder
lib.rstokio-fmt-encoder
version0.2.0
sourcesrc
created_at2017-10-16 23:42:26.037408
updated_at2017-10-17 12:13:06.979546
descriptionA Tokio Encoder for Debug and Display
homepage
repositoryhttps://github.com/paulkernfeld/tokio-fmt-encoder
max_upload_size
id35920
size5,600
Paul Kernfeld (paulkernfeld)

documentation

https://crates.io/crates/tokio-fmt-encoder

README

tokio-fmt-encoder

Encode items that implement formatting traits like Debug and Display.

To encode an item that implements Debug:

extern crate bytes;
extern crate tokio_fmt_encoder;
extern crate tokio_io;

fn main() {
    use bytes::BytesMut;
    use std::fmt::Formatter;
    use tokio_fmt_encoder::DebugEncoder;
    use tokio_io::codec::Encoder;

    let to_encode = Some(10);
    let mut buffer = BytesMut::with_capacity(64);
    let mut encoder: DebugEncoder<Option<usize>> = Default::default();
    encoder.encode(to_encode, &mut buffer).unwrap();
    assert_eq!(&buffer.take(), &"Some(10)\n");
}

To encode an item that implements Display:

extern crate bytes;
extern crate tokio_fmt_encoder;
extern crate tokio_io;

fn main() {
    use bytes::BytesMut;
    use std::fmt::Formatter;
    use tokio_fmt_encoder::DisplayEncoder;
    use tokio_io::codec::Encoder;

    let to_encode = String::from("hello");
    let mut buffer = BytesMut::with_capacity(64);
    let mut encoder: DisplayEncoder<String> = Default::default();
    encoder.encode(to_encode, &mut buffer).unwrap();
    assert_eq!(&buffer.take(), &"hello\n");
}

License: MIT/Apache-2.0

Commit count: 6

cargo fmt