Rust是否在tee(2)
中为std::io
绑定?如果没有绑定,如何在Rust程序中获得该功能?
答案 0 :(得分:4)
tee
方法existed in the standard library,但it was deprecated in 1.6。
您可以使用the tee crate来获得相同的功能:
extern crate tee;
use tee::TeeReader;
use std::io::Read;
fn main() {
let mut reader = "It's over 9000!".as_bytes();
let mut teeout = Vec::new();
let mut stdout = Vec::new();
{
let mut tee = TeeReader::new(&mut reader, &mut teeout);
let _ = tee.read_to_end(&mut stdout);
}
println!("tee out -> {:?}", teeout);
println!("std out -> {:?}", stdout);
}