11个版本 (6个破坏性更新)
0.6.1 | 2021年11月19日 |
---|---|
0.6.0 |
|
0.5.0 | 2021年11月14日 |
0.4.1 | 2021年5月19日 |
0.0.0 | 2021年3月27日 |
#345 in 调试
每月116次下载
14KB
167 代码行
在开发时打印调试信息
这个库有什么作用?
- 打印友好的调试信息;
- 不会影响发布版本的性能;
使用方法
将此添加到您的 Cargo.toml
[dependencies]
develop_debug = "0.6.1"
使用 develop_debug!
use std::collections::HashMap;
use develop_debug::*;
// Standard usage
#[test]
fn test_develop_debug() {
let x = "dear X";
let say = "hello world!";
let vec = vec!["a", "b", "c"];
let map = HashMap::from([("a", (Some("a"), "a")), ("b", (Some("b"), "b"))]);
let title2 = "balabala...";
develop_debug!(output method);
develop_debug!(title "example {}",title2);
develop_debug!(step "do something...{}", say);
develop_debug!(vars x,say,vec,map);
develop_debug!(done "genius {}",x);
develop_debug!(error "dude, this road is blocked. {}",x);
develop_debug!(
"{}",
"Use it just as you would with the `println!()` macro."
);
}
// Using the shortcut, print the same result as above.
#[test]
fn test_develop_debug_shortcut() {
let x = "dear X";
let say = "hello world!";
let vec = vec!["a", "b", "c"];
let map = HashMap::from([("a", (Some("a"), "a")), ("b", (Some("b"), "b"))]);
let title2 = "balabala...";
dd____show!();
dd___title!("example {}", title2);
dd____step!("do something...{}", say);
dd____vars!(x, say, vec, map);
dd____done!("genius {}", x);
dd___error!("dude, this road is blocked. {}", x);
dd________!(
"{}",
"Use it just as you would with the `println!()` macro."
);
}
#[test]
fn test_output_range_control() {
dd____show!(); // Output only messages for the current method
dd____step!("current method 1 .."); // output
other(); // ignored
dd____show!(global); // Outputs all messages for all methods
dd____step!("current method 2 .."); // output
other(); // output
dd____hide!(global);
}
fn other() {
dd____step!("other method");
}
调试模式下的输出
❲ tests/how_to_use.rs:36 ❳ 🍀 example balabala...
❲ tests/how_to_use.rs:37 ❳ 🦀 do something...hello world!
❲ tests/how_to_use.rs:38 ❳ 🔹 ‹ x › = "dear X"
❲ tests/how_to_use.rs:38 ❳ 🔹 ‹ say › = "hello world!"
❲ tests/how_to_use.rs:38 ❳ 🔹 ‹ vec › = [
› "a",
› "b",
› "c",
]
❲ tests/how_to_use.rs:38 ❳ 🔹 ‹ map › = {
› "b": (
› Some(
› "b",
› ),
› "b",
› ),
› "a": (
› Some(
› "a",
› ),
› "a",
› ),
}
❲ tests/how_to_use.rs:39 ❳ 🌱 done. genius dear X
❲ tests/how_to_use.rs:40 ❳ 💥 error. dude, this road is blocked. dear X
❲ tests/how_to_use.rs:41 ❳ 🐰 Use it just as you would with the `println!()` macro.
# output_range_control
🦀 current method 1 ..
🦀 current method 2 ..
🦀 other method
在 --release
模式下无输出。
develop_debug!
快捷键的优点是什么?
😬 我认为在源代码中很容易识别;
🤤 我认为在 VS Code
中提示方便;
🤓 我认为它可以从视觉上分割代码;
develop_debug!
宏会影响代码性能吗?
- 它根本不会影响代码性能;
- 在编译到发布版本时,
develop_debug!
实际上展开为空;
如果文档在语义上不够流畅
🥺,请原谅我英语的不足。所有文档都由翻译软件解释;如果您能提供更好的翻译,请通过[email protected]联系我;
希望这个简单的库对您有所帮助。
😌 😌 😌 😌 😌 😌