Skip to content

Instantly share code, notes, and snippets.

@d6y
Forked from rust-play/playground.rs
Created December 16, 2020 09:40
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 d6y/6d0586d96fc64fdd0f16eaf31a27fafd to your computer and use it in GitHub Desktop.
Save d6y/6d0586d96fc64fdd0f16eaf31a27fafd to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
trait Debuggable {
fn debug(self) -> Self;
}
impl<T> Debuggable for T
where
T: Sized + std::fmt::Debug,
{
fn debug(self) -> Self {
dbg!(self)
}
}
fn main() {
let _x = "hello".debug();
let _ys = (0..10)
.debug()
.map(|x| x * 3)
.collect::<Vec<usize>>()
.debug();
}
@d6y
Copy link
Author

d6y commented Dec 16, 2020

Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f40295c6954f5b612397ca199d991eaf

Output:

   Compiling playground v0.0.1 (/playground)
    Finished dev [unoptimized + debuginfo] target(s) in 1.30s
     Running `target/debug/playground`
[src/main.rs:10] self = "hello"
[src/main.rs:10] self = 0..10
[src/main.rs:10] self = [
    0,
    3,
    6,
    9,
    12,
    15,
    18,
    21,
    24,
    27,
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment