Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created May 3, 2022
Embed
What would you like to do?
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