This repository was archived by the owner on Dec 2, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55
66## [ Unreleased]
77
8+ - Adds a feature to work around JLink quirks
9+ - Adds a dbg! macro using heprintln
10+
811## [ v0.3.4] - 2019-04-22
912
1013### Fixed
Original file line number Diff line number Diff line change @@ -85,3 +85,29 @@ macro_rules! heprintln {
8585 $crate:: export:: hstderr_fmt( format_args!( concat!( $s, "\n " ) , $( $tt) * ) )
8686 } ;
8787}
88+
89+ /// Macro that prints and returns the value of a given expression
90+ /// for quick and dirty debugging. Works exactly like `dbg!` in
91+ /// the standard library, replacing `eprintln` with `heprintln`.
92+ #[ macro_export]
93+ macro_rules! dbg {
94+ ( ) => {
95+ $crate:: hprintln!( "[{}:{}]" , file!( ) , line!( ) ) ;
96+ } ;
97+ ( $val: expr) => {
98+ // Use of `match` here is intentional because it affects the lifetimes
99+ // of temporaries - https://stackoverflow.com/a/48732525/1063961
100+ match $val {
101+ tmp => {
102+ $crate:: hprintln!( "[{}:{}] {} = {:#?}" ,
103+ file!( ) , line!( ) , stringify!( $val) , & tmp) ;
104+ tmp
105+ }
106+ }
107+ } ;
108+ // Trailing comma with single argument is ignored
109+ ( $val: expr, ) => { $crate:: dbg!( $val) } ;
110+ ( $( $val: expr) ,+ $( , ) ?) => {
111+ ( $( $crate:: dbg!( $val) ) ,+, )
112+ } ;
113+ }
You can’t perform that action at this time.
0 commit comments