Skip to content

Instantly share code, notes, and snippets.

@barseghyanartur
Created February 2, 2023 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barseghyanartur/7d78eb3d742ccb645eec66607372ca1a to your computer and use it in GitHub Desktop.
Save barseghyanartur/7d78eb3d742ccb645eec66607372ca1a to your computer and use it in GitHub Desktop.
Rust `dbg!` macro learnings

Another learning about the fantastic dbg! macro: always pass vars as references!

This works:

let mut s = String::from("hello");
dbg!(&s);

s.push_str(", world!");
dbg!(&s);

This fails:

let mut s = String::from("hello");
dbg!(s);

s.push_str(", world!");
dbg!(s);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment