0.1.0 |
|
---|
#52 in #quality
8KB
93 lines
Spotlight
Warning
Spotlight is currently considered experimental / alpha level quality
spotlight!
is a drop in replacement macro for std::dbg!
which adds additional information, has colored output, and can be called in a postfix position (e.g. between chaining method calls, as .spotlight("label")
).
Examples
Note
The thread and function name are the same in these examples as they were taken from test runs, which name the main thread with the same name as the test function
Macro
use spotlight::spotlight;
fn swap() {
let mut left = 5;
let mut right = 3;
spotlight!(&left);
spotlight!(&right);
std::mem::swap(&mut left, &mut right);
spotlight!(&left);
spotlight!(&right);
}
outputs
[time 1659217308153] [file tests/mod.rs:18] [fn mod::swap] [thread swap] [addr 0x16de8d350] &left = 5
[time 1659217308153] [file tests/mod.rs:19] [fn mod::swap] [thread swap] [addr 0x16de8d354] &right = 3
[time 1659217308153] [file tests/mod.rs:21] [fn mod::swap] [thread swap] [addr 0x16de8d350] &left = 3
[time 1659217308153] [file tests/mod.rs:22] [fn mod::swap] [thread swap] [addr 0x16de8d354] &right = 5
Method
use spotlight::Spotlight;
fn method() {
let _ = "test"
.chars()
.spotlight("as_chars")
.map(|char| char.to_uppercase().to_string())
.spotlight("mapped")
.collect::<String>()
.spotlight("new_string");
}
outputs
[time 1659217480013] [thread method] [addr 0x16bc020d8] as_chars = Chars([
't',
'e',
's',
't',
])
[time 1659217480014] [thread method] [addr 0x16bc01d68] mapped = Map {
iter: Chars([
't',
'e',
's',
't',
]),
}
[time 1659217480014] [thread method] [addr 0x16bc01d50] new_string = "TEST"
Prior Art
- The
Spotlight
trait uses the implementation used in tap - The
spotlight!
macro is derived from thedbg!
macro - The method of deriving the current function name uses the implementation in this StackOverflow answer
Dependencies
~0–9.5MB
~43K SLoC