Rust是否对tee(2)具有绑定?

时间:2018-08-14 00:55:57

标签: linux io rust

Rust是否在tee(2)中为std::io绑定?如果没有绑定,如何在Rust程序中获得该功能?

1 个答案:

答案 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);
}

example from the repo