convert-chain

Crates.ioconvert-chain
lib.rsconvert-chain
version0.1.3
sourcesrc
created_at2023-05-25 11:49:22.129588
updated_at2023-05-26 05:03:27.515074
descriptionA simple chain converter
homepage
repositoryhttps://github.com/Berberine/convert-chain
max_upload_size
id874241
size6,068
Berberine (Berberine)

documentation

README

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));
Commit count: 4

cargo fmt