Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Rust have bindings for tee(2)?

Tags:

linux

io

rust

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?

like image 579
Lombard Avatar asked Jun 09 '26 08:06

Lombard


1 Answers

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

(example from the repo)

like image 58
ozkriff Avatar answered Jun 12 '26 12:06

ozkriff