1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use std::fs::OpenOptions;
use std::fs::File;
use std::io;
use redirect::Redirect;
fn null() -> io::Result<File> {
    OpenOptions::new().write(true).open("/dev/null")
}
pub struct Gag(Redirect<File>);
impl Gag {
    
    pub fn stdout() -> io::Result<Gag> {
        let nul = try!(null());
        let redir = try!(Redirect::stdout(nul));
        Ok(Gag(redir))
    }
    
    pub fn stderr() -> io::Result<Gag> {
        let nul = try!(null());
        let redir = try!(Redirect::stderr(nul));
        Ok(Gag(redir))
    }
}