Skip to main content

FromChain

Derive Macro FromChain 

Source
#[derive(FromChain)]
{
    // Attributes available to this derive:
    #[from_chain]
}
Expand description

Implement ::std::convert::From through a chain of intermediate types.

ยงExample

struct Foo;

struct Bar;

struct Baz;

impl From<Foo> for Bar { fn from(_foo: Foo) -> Self { Self } }

impl From<Bar> for Baz { fn from(_bar: Bar) -> Self { Self } }

impl From<Baz> for MyStruct { fn from(_baz: Baz) -> Self { Self } }

#[derive(mkutils_macros::FromChain)]
#[from_chain(Foo, Bar, Baz)]
struct MyStruct;

// adds

// impl From<Foo> for MyStruct {
//     fn from(foo: Foo) -> Self {
//         Self::from(Baz::from(Bar::from(foo)))
//     }
// }

// as can be seen in

let _my_struct: MyStruct = Foo.into();