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

gag

Gag, 重定向或暂停 stdout/stderr 输出。目前仅支持 *nix 操作系统。

12 个版本 (1 个稳定版本)

使用旧的 Rust 2015

1.0.0 2021年5月30日
0.1.10 2018年4月20日
0.1.9 2016年1月19日
0.1.6 2015年5月1日
0.1.5 2015年4月15日

#80Unix APIs

Download history 10562/week @ 2024-04-09 11508/week @ 2024-04-16 11139/week @ 2024-04-23 9487/week @ 2024-04-30 10075/week @ 2024-05-07 10229/week @ 2024-05-14 6881/week @ 2024-05-21 9809/week @ 2024-05-28 9672/week @ 2024-06-04 10164/week @ 2024-06-11 7685/week @ 2024-06-18 8158/week @ 2024-06-25 6850/week @ 2024-07-02 8931/week @ 2024-07-09 9680/week @ 2024-07-16 8665/week @ 2024-07-23

35,425 每月下载量
82 个 crate 中使用 (48 个直接使用)

MIT 许可证

13KB
202

重定向和/或哑铃 stdout/stderr。

Build Status

文档(含示例): https://docs.rs/gag/

限制

  • 如果已调用其他函数设置了 std::io::set_print(目前不稳定),则无法正常工作。遗憾的是,此函数实际上并没有重定向 stdio 文件描述符,它只是替换了 std::io::stdout 写入器。
  • 在 rust 测试用例中无法工作。rust 测试用例使用 std::io::set_print 重定向 stdout。不过,您可以在运行测试时使用 --nocapture 参数来解决这个问题。

待办事项

  • 通用
    • 更好的错误处理?
  • 重定向
    • 泛型引用。也就是说,接受 AsRawFd 或 AsRawFd 的引用。遗憾的是,我不知道这是否可能。借用无法工作,因为我真的想有以下的约束: impl<F> Redirect<F> where F: BorrowMut<T>, T: AsMut<AsRawFd> 因此我可以写 file.borrow_mut().as_mut() 但这将是模糊的...
  • 缓冲区
    • 如果可能,则在读取时释放缓冲区(FALLOC_FL_PUNCH_HOLE)。

依赖关系

~2–11MB
~126K SLoC