diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2018-12-05 22:09:10 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2018-12-05 22:09:10 +0200 |
commit | 8ceeb0bf7ace0527b03dd23b28bffa61d4d92bd8 (patch) | |
tree | 218437ed59d4069c45d1705974a08a079e1c8e4e /src | |
parent | fcaa7aed93f4a5a634a6673ba4784bd251a5151c (diff) |
Added a convenient debug macro
Prints the expression along with it's value. Thanks to Steve Donovan
for giving me the idea at the Rust meetup!
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/day_5.rs | 4 | ||||
-rw-r--r-- | src/lib.rs | 8 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/bin/day_5.rs b/src/bin/day_5.rs index d689e34..2b24d4c 100644 --- a/src/bin/day_5.rs +++ b/src/bin/day_5.rs @@ -17,7 +17,7 @@ fn main() -> Result<(), Box<Error>> { polymer }; - println!("Base length after reducing: {}", polymer.len()); + debug!(polymer.len()); let mut min_length = polymer.len(); @@ -28,7 +28,7 @@ fn main() -> Result<(), Box<Error>> { min_length = cmp::min(min_length, polymer_without_char.len()); } - println!("Minimum length found: {}", min_length); + debug!(min_length); Ok(()) } @@ -21,3 +21,11 @@ pub fn preprocess_file_lines(lines: Vec<String>) -> Vec<String> { .map(|line| line.trim_right().to_string()) .collect() } + + +#[macro_export] +macro_rules! debug { + ( $x:expr ) => { + println!("{} = {:?}", stringify!($x), $x); + }; +} |