0.1.0 |
|
---|
#47 in #quality
8KB
93 代码行
Spotlight
警告
Spotlight目前被视为实验性/alpha级别质量
spotlight!
是 std::dbg!
的直接替换宏,它添加了额外的信息,具有彩色输出,并且可以在后缀位置调用(例如,在方法链调用之间,如 .spotlight("标签")
)。

示例
注意
这些示例中线程和函数名称相同,因为它们是从测试运行中获取的,测试运行使用与测试函数相同的名称命名主线程
宏
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);
}
输出
[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
方法
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");
}
输出
[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"
先前的技术
Spotlight
特性使用了 tap 中的实现spotlight!
宏是从dbg!
宏 派生的- 获取当前函数名称的方法使用了 此 StackOverflow 答案 中的实现
依赖关系
~0–10MB
~56K SLoC