use redirect::Redirect;
use std::fs::File;
use std::fs::OpenOptions;
use std::io;
fn null() -> io::Result<File> {
#[cfg(windows)]
return OpenOptions::new().write(true).open("NUL");
#[cfg(unix)]
return OpenOptions::new().write(true).open("/dev/null");
}
pub struct Gag(Redirect<File>);
impl Gag {
pub fn stdout() -> io::Result<Gag> {
Ok(Gag(Redirect::stdout(null()?)?))
}
pub fn stderr() -> io::Result<Gag> {
Ok(Gag(Redirect::stderr(null()?)?))
}
}