2 unstable releases
Uses old Rust 2015
0.2.0 | Oct 17, 2017 |
---|---|
0.1.0 | Oct 16, 2017 |
#197 in #encoder
Used in tokio-stdout
6KB
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
Dependencies
~615KB
~11K SLoC