1 unstable release
Uses new Rust 2024
0.1.0 | Mar 2, 2025 |
---|
#6 in #quiet
141 downloads per month
13KB
135 lines
shaddup-rs
Shut up your Rust program('s stdout and stderr).
Works on Unix only (so far).
Usage
use shaddup::run_quietly;
let result = run_quietly(|| {
println!("This will not be printed");
eprintln!("neither will this");
123
});
assert_eq!(result.unwrap(), 123);
This is similar to gag
:
that crate has a different API,
based around guard handles instead of closures.
It supports Unix and Windows targets.
Cargo features
allow_unsupported
: If this is enabled, and you're building on an unsupported target, then the library will be a no-op. (If this feature is not provided on an unsupported target, then this will fail to compile.)no_op
: If this is enabled, then the library will be a no-op, even if the target is supported. This can be useful for debugging.
lib.rs
:
shaddup
!
This library prevents your program from printing to stdout and stderr by using platform-specific utilities to redirect them to /dev/null (or equivalent).
By default, this will cause a compile-error if the platform is not supported,
because we don't know how to perform the redirection.
If you'd like the library to be a no-op in these cases,
use the allow_unsupported
feature.
If you want to make this library be a no-op even if the platform is supported
(for example, for debugging),
add the no_op
feature:
this turns the entire library into a no-op.
Usage
use shaddup::run_quietly;
let result = run_quietly(|| {
println!("This will not be printed");
eprintln!("This will also not be printed");
123
});
assert_eq!(result.unwrap(), 123);
Features
no_op
: turns the entire library into a no-op.allow_unsupported
: turns the library into a no-op if the platform is supported (otherwise, the library will cause a compile-error).
See also
gag
is another library that implements this functionality.
It uses a different API, based on guards
rather than closures.
It supports Unix and Windows.
Dependencies
~1.5MB
~35K SLoC