Reputation: 187
Does Rust have bindings for tee(2)
in std::io
or otherwise? And if there are no bindings, how would I get that functionality in a Rust program?
Upvotes: 3
Views: 261
Reputation: 1359
The tee
method existed in the standard library, but it was deprecated in 1.6.
You can use the tee crate to get the same functionality:
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);
}
Upvotes: 6