control_code/
format.rs

1//            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2//                    Version 2, December 2004
3//
4// Copyleft (ↄ) meh. <meh@schizofreni.co> | http://meh.schizofreni.co
5//
6// Everyone is permitted to copy and distribute verbatim or modified
7// copies of this license document, and changing it is allowed as long
8// as the name is changed.
9//
10//            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11//   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12//
13//  0. You just DO WHAT THE FUCK YOU WANT TO.
14
15use std::io::{self, Write};
16
17pub trait Format {
18	fn fmt<W: Write>(&self, f: W) -> io::Result<()>;
19}
20
21#[inline]
22pub fn format<T: Format>(value: &T) -> Vec<u8> {
23	let mut result = Vec::new();
24	value.fmt(&mut result).unwrap();
25
26	result
27}
28
29#[inline]
30pub fn format_to<T: Format, W: Write>(output: W, value: &T) -> io::Result<()> {
31	value.fmt(output)
32}