#stdout #stderr #stdio #redirect

gag

Gag, redirect, or hold stdout/stderr output. Currently only *nix operating systems are supported.

12 releases (1 stable)

Uses old Rust 2015

1.0.0 May 30, 2021
0.1.10 Apr 20, 2018
0.1.9 Jan 19, 2016
0.1.6 May 1, 2015
0.1.5 Apr 15, 2015

#23 in Unix APIs

Download history 5128/week @ 2021-07-05 5241/week @ 2021-07-12 5056/week @ 2021-07-19 5625/week @ 2021-07-26 6991/week @ 2021-08-02 7781/week @ 2021-08-09 6403/week @ 2021-08-16 6861/week @ 2021-08-23 7605/week @ 2021-08-30 8003/week @ 2021-09-06 8337/week @ 2021-09-13 8588/week @ 2021-09-20 8446/week @ 2021-09-27 9356/week @ 2021-10-04 11092/week @ 2021-10-11 9860/week @ 2021-10-18

14,972 downloads per month
Used in 42 crates (25 directly)

MIT license

13KB
202 lines

Redirect and/or gag stdout/stderr.

Build Status

Documentation (with examples): https://docs.rs/gag/

Limitations

  • Won't work if something else has called std::io::set_print (currently unstable). Unfortunately, this function doesn't actually redirect the stdio file descriptor, it just replaces the std::io::stdout writer.
  • Won't work in rust test cases. The rust test cases use std::io::set_print to redirect stdout. You can get around this though by using the --nocapture argument when running your tests.

TODO:

  • General:
    • Better error handling?
  • Redirect:
    • Be generic over references. That is, accept both a reference to an AsRawFd or an AsRawFd. Unfortunately, I don't know if this is even possible. Borrow doesn't work because I really want the following constraint: impl<F> Redirect<F> where F: BorrowMut<T>, T: AsMut<AsRawFd> so I can write file.borrow_mut().as_mut() but that would be ambiguous...
  • Buffer:
    • Deallocate the buffer as it is read (FALLOC_FL_PUNCH_HOLE) if possible.

Dependencies

~0.7–1.3MB
~28K SLoC