#stdout-stderr #stdout #stderr #redirect #stdio #operating-systems #file-descriptor

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

#135 in Unix APIs

Download history 9520/week @ 2023-12-14 6131/week @ 2023-12-21 5058/week @ 2023-12-28 9290/week @ 2024-01-04 9146/week @ 2024-01-11 11768/week @ 2024-01-18 9413/week @ 2024-01-25 10442/week @ 2024-02-01 8218/week @ 2024-02-08 9435/week @ 2024-02-15 10371/week @ 2024-02-22 10085/week @ 2024-02-29 9185/week @ 2024-03-07 9321/week @ 2024-03-14 11297/week @ 2024-03-21 8760/week @ 2024-03-28

40,547 downloads per month
Used in 71 crates (44 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

~2–12MB
~134K SLoC