Skip to content

Commit

Permalink
Add column number to dbg output
Browse files Browse the repository at this point in the history
  • Loading branch information
wcampbell0x2a committed Jan 20, 2024
1 parent 110e61b commit 251b162
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# dbg_hex
display dbg result in hexadecimal `{:#x?}` format.
dbg_hex
===========================

[<img alt="github" src="https://img.shields.io/badge/github-wcampbell0x2a/dbg_hex-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/wcampbell0x2a/dbg_hex)
[<img alt="crates.io" src="https://img.shields.io/crates/v/dbg_hex.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/dbg_hex)
[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-dbg_hex-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" height="20">](https://docs.rs/dbg_hex)
[<img alt="build status" src="https://img.shields.io/github/actions/workflow/status/wcampbell0x2a/dbg_hex/main.yml?branch=master&style=for-the-badge" height="20">](https://github.com/wcampbell0x2a/dbg_hex/actions?query=branch%3Amaster)

Display dbg result in hexadecimal `{:#x?}` format.

# usage
Replace `dbg!()` with `dbg_hex!()`
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ macro_rules! dbg_hex {
// `$val` expression could be a block (`{ .. }`), in which case the `eprintln!`
// will be malformed.
() => {
eprintln!("[{}:{}]", file!(), line!());
eprintln!("[{}:{}:{}]", file!(), line!(), column!());
};
($val:expr $(,)?) => {
// Use of `match` here is intentional because it affects the lifetimes
// of temporaries - https://stackoverflow.com/a/48732525/1063961
match $val {
tmp => {
eprintln!("[{}:{}] {} = {:#x?}",
file!(), line!(), stringify!($val), &tmp);
eprintln!("[{}:{}:{}] {} = {:#x?}",
file!(), line!(), column!(), stringify!($val), &tmp);
tmp
}
}
Expand Down

0 comments on commit 251b162

Please sign in to comment.