chain-debug 0.1.1

Injecting debug without rewriting chain-calling code
Documentation
//! # Example
//!
//! ```rust
//! use chain_debug::DebugExt;
//!
//! struct A {
//!     inner: B,
//! }
//!
//! #[derive(Debug)]
//! struct B {
//!     s: String,
//! }
//!
//! impl A {
//!     fn inner(&self) -> &B {
//!         &self.inner
//!     }
//! }
//!
//! let a = A { ... };
//!
//! a
//!   .inner()
//!   .debug()
//!   .s
//!   .debug()
//! ```
//!

use std::fmt::Debug;

pub trait DebugExt {
    fn debug(&self) -> &Self
    where
        Self: Debug,
    {
        println!("{self:?}");
        self
    }
}

impl<D: Debug> DebugExt for D {}

#[test]
fn test() {
    #[derive(Debug)]
    struct S {
        inner: String,
    }

    impl S {
        fn upper(&self) -> &str {
            &self.inner
        }
    }

    struct G {
        inner: S,
    }

    impl G {
        fn inner(&self) -> &S {
            &self.inner
        }
    }

    let s = S {
        inner: "foo".to_string(),
    };
    let g = G { inner: s };

    g.inner().debug().upper().debug();
}