Guest User

Untitled

a guest
Jan 20th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #[macro_export]
  2. macro_rules! dbg {
  3. ($expr:expr) => (dbg!("{:#?}", $expr));
  4. ($fmt:expr, $expr:expr$(, $opt:expr)*) => {
  5. match $expr {
  6. expr => {
  7. eprintln!(concat!("[{}:{}] {} = ", $fmt), file!(), line!(), stringify!($expr), &expr$(, $opt)*);
  8. expr
  9. }
  10. }
  11. }
  12. }
  13.  
  14. fn main() {
  15. let t = dbg!(2 + 1);
  16. // instead of this:
  17. let _: u64 = dbg!((1 << 63) | (t << 8));
  18.  
  19. // this gives a nicer representation:
  20. let _: u64 = dbg!("0x{:x}", (1 << 63) | (t << 8));
  21.  
  22. // this is also possible:
  23. let _: u64 = dbg!("0x{:x} with {}", (1 << 63) | (t << 8), t);
  24. }
Add Comment
Please, Sign In to add comment