Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created May 3, 2022 16:55
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 rust-play/5b0ef92f425b2187c501b2d60492bb6d to your computer and use it in GitHub Desktop.
Save rust-play/5b0ef92f425b2187c501b2d60492bb6d to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
trait ChainDebug {
fn debug(self) -> Self
where
Self: Sized + std::fmt::Debug,
{
dbg!(self)
}
}
impl ChainDebug for X {}
impl ChainDebug for Y {}
impl ChainDebug for Z {}
#[derive(Debug)]
struct X {}
impl X {
fn start() -> X {
X {}
}
fn hoge(self) -> Y {
Y {}
}
}
#[derive(Debug)]
struct Y {}
impl Y {
fn fuga(self) -> Z {
Z {}
}
}
#[derive(Debug)]
struct Z {}
impl Z {
fn piyo(self) -> i32 {
10
}
}
fn main() {
let v = X::start().debug().hoge().debug().fuga().debug().piyo();
println!("{}", v);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment