#fmt #io #Write #wrapper #bridge

fmt2io

A bridge between std::io::Write and std::fmt::Write

1 unstable release

0.1.0 Nov 6, 2018

#8 in #fmt

Download history 5/week @ 2018-11-06 8/week @ 2018-11-13 14/week @ 2018-11-20 2/week @ 2018-11-27 7/week @ 2018-12-04 2/week @ 2018-12-11 3/week @ 2018-12-18 7/week @ 2018-12-25

1 downloads per month

MITNFA license

4KB

Fmt to IO

A bridge between std::io::Write and std::fmt::Write.

About

Have you ever implemented a nice algorithm that generically uses fmt::Write only to find out it doesn't work with io::Write? Worry no more - this is the solution!

This crate provides a simple write function which takes your io::Writer, converts it to fmt::Writer and provides it to your closure. This way, you can easily bridge the two traits and have truly generic code.

License

MITNFA


lib.rs:

Have you ever implemented a nice algorithm that generically uses fmt::Write only to find out it doesn't work with io::Write? Worry no more - this is the solution!

This crate provides a simple write function which takes your io::Writer, converts it to fmt::Writer and provides it to your closure. This way, you can easily bridge the two traits and have truly generic code.

Example

let mut out = Vec::new();

use std::fmt::Write;

fmt2io::write(&mut out, |writer| write!(writer, "Hello world!")).unwrap();
assert_eq!(out, "Hello world!".as_bytes());

No runtime deps