Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

- Adds a feature to work around JLink quirks
- Adds a dbg! macro using heprintln
- Now Rust 2018 edition

## [v0.3.4] - 2019-04-22

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@
//! `dbg!` returns a given expression and prints it using `heprintln!` including context
//! for quick and dirty debugging.
//!
//! Panics if `heprintln!` returns an error.
//!
//! Example:
//!
//! ```
Expand Down
9 changes: 5 additions & 4 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,20 @@ macro_rules! heprintln {

/// Macro that prints and returns the value of a given expression
/// for quick and dirty debugging. Works exactly like `dbg!` in
/// the standard library, replacing `eprintln` with `heprintln`.
/// the standard library, replacing `eprintln` with `heprintln`,
/// which it unwraps.
#[macro_export]
macro_rules! dbg {
() => {
$crate::hprintln!("[{}:{}]", file!(), line!());
$crate::heprintln!("[{}:{}]", file!(), line!()).unwrap();
};
($val:expr) => {
// Use of `match` here is intentional because it affects the lifetimes
// of temporaries - https://stackoverflow.com/a/48732525/1063961
match $val {
tmp => {
$crate::hprintln!("[{}:{}] {} = {:#?}",
file!(), line!(), stringify!($val), &tmp);
$crate::heprintln!("[{}:{}] {} = {:#?}",
file!(), line!(), stringify!($val), &tmp).unwrap();
tmp
}
}
Expand Down