| Crates.io | workspace-filter-build |
| lib.rs | workspace-filter-build |
| version | 0.1.0 |
| created_at | 2025-08-14 21:28:53.082203+00 |
| updated_at | 2025-08-14 21:28:53.082203+00 |
| description | Simple framework to compile env filters for all packages in a workspace |
| homepage | |
| repository | https://github.com/ozwaldorf/workspace-filter |
| max_upload_size | |
| id | 1795833 |
| size | 19,133 |
Simple framework to compile env filters for all packages in a workspace.
First, add the two dependencies to your crate:
[dependencies]
workspace-filter = "0.1"
[build-dependencies]
workspace-filter-build = "0.1"
Then, call the build function in your build.rs file:
fn main() -> Result<(), Box<dyn std::error::Error> {
// NOTE: This will rerun the entire build script if Cargo.lock changes
workspace_filter_build::build()?;
}
The macro can then be used in your crate, with a few example use-cases shown below:
If you only care to set the filter for your workspace dependencies:
let filter = workspace_filter!("debug");
let env_filter = EnvFilter::builder().parse_lossy(filter);
Manual filters can be included, for example to make workspace crates at debug and everything else at info:
let filter = workspace_filter!("debug", "info");
let env_filter = EnvFilter::builder().parse_lossy(filter);
In the catchall argument, {level} can be also used anywhere to substitute the given workspace level.
let filter = workspace_filter!("debug", "trace,my-bin={level}");
let env_filter = EnvFilter::builder().parse_lossy(filter);
Example that overrides with RUST_LOG, or falls back to increasing the
verbosity for the workspace and other deps depending on a given number
let filter = std::env::var("RUST_LOG").unwrap_or_else(|_| {
// Fallback which is directed by the verbosity flag
match args.verbose {
0 => "info".into(),
1 => workspace_filter!("debug", "info"),
2 => workspace_filter!("trace", "info"),
3 => workspace_filter!("trace", "debug"),
_ => "trace".into(),
}
});
let env_filter = EnvFilter::builder().parse_lossy(filter);