Crates.io | tokio-fmt-encoder |
lib.rs | tokio-fmt-encoder |
version | 0.2.0 |
source | src |
created_at | 2017-10-16 23:42:26.037408 |
updated_at | 2017-10-17 12:13:06.979546 |
description | A Tokio Encoder for Debug and Display |
homepage | |
repository | https://github.com/paulkernfeld/tokio-fmt-encoder |
max_upload_size | |
id | 35920 |
size | 5,600 |
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