Crate convert_chain

Source
Expand description

§convert-chain

Crates.io docs.rs Crates.io Crates.io

A tiny crate for chain type converter. There is only one macro convert_chian in it

Assuming there are 3 sturct with following relationship.

struct A;
struct B;
struct C;

impl From<B> for A { ... }
impl From<C> for B { ... }

You can use the macro to directly convert an expression or create a closure for the convert.

  • Directly convert

    let c = C;
    let a = convert_chain!(c; B, A);
  • Create a closure

    let c = C;
    let f = convert_chain!(B, A);
    let a = f(c);

Both of the above methods are equivalent to

let c = C;
let a = A::from(B::from(c));

Macros§

convert_chain