| Crates.io | print-run |
| lib.rs | print-run |
| version | 0.1.2 |
| created_at | 2025-07-10 09:22:28.701202+00 |
| updated_at | 2025-07-14 08:58:39.796962+00 |
| description | A stylish procedural macro for tracing function execution with color, indentation, timestamps, and duration. |
| homepage | |
| repository | https://github.com/HeyJ0e/print-run-rs |
| max_upload_size | |
| id | 1746068 |
| size | 47,451 |

print-run is a procedural macro for Rust that automatically prints messages when a function starts and finishes. It supports colorized output, timestamps, duration display, indentation for nested calls, and more.
Itβs designed to be a lightweight and stylish debugging or tracing tool β ideal for building skeletons, quick experiments, or educational projects.
Install using Cargo:
cargo add print-run
Or add this crate to your dependencies in Cargo.toml:
[dependencies]
print-run = "0.1"
use print_run::print_run;
#[print_run]
fn my_function() {
let x = 5;
msg!("Some value: {}", x);
}
my_function();
Output:
my_function starting
Some value: 5
my_function ended
#[print_run(colored, duration, indent, supress_labels, timestamps)]
fn my_function() { ... }
Output (color not shown in markdown):
15:21:29.964 β my_function
15:21:29.964 β Some value: 5
15:21:29.964 β my_function [9.50Β΅s]
struct MyStruct;
#[print_run(indent)]
impl MyStruct {
fn static_fn() { ... }
fn instance_fn(&self) { ... }
}
Output:
β MyStruct::static_fn starting
β MyStruct::static_fn ended
β MyStruct.instance_fn starting
β MyStruct.instance_fn ended
[!WARNING] Only inline modules are supported due to Rustβs procedural macro limitations.
Every function inside the module will inherit the #[print_run(...)] attributes, including implementations. You can override them locally or exclude specific functions using #[print_run(skip)].
The msg! macro is available in all instrumented functions.
#[print_run(colored, indent)]
mod my_module {
fn something() {}
fn another() {}
#[print_run(duration)]
fn overridden() {}
#[print_run(skip)]
fn not_printed() {}
struct MyStruct;
impl MyStruct {
fn static_fn() {}
fn method_1(&self) {}
fn method_2(&self) {}
}
}
You can define defaults (once per crate) by placing print_run_defaults anywhere in the crate:
#[print_run_defaults(indent)]
βΉοΈ Note: Rust currently does not support custom crate-wide attributes like
#![print_run_defaults()].
The following arguments are supported by #[print_run(...)] and #[print_run_defaults(...)]:
| Argument | Description | Notes |
|---|---|---|
colored |
Enable ANSI color output | |
duration |
Show function execution duration | Auto-selects units (s/ms/Β΅s/ns) |
indent |
Draw indented call hierarchy | |
skip |
Skip the current function/module | Ignores all other arguments |
supress_labels |
Hide starting / ended labels |
|
timestamps |
Show timestamps in log output | Format: HH:mm:ss.sss |
All arguments can be combined but skip will override the rest.
msg!The msg! macro works like println!, but:
indent is enabled)timestamps is enabled)#[print_run]println! when used in skipped functionsLicensed under MIT.
Contributions, suggestions, and issues are welcome! Feel free to fork the repo or open a PR.