Crates.io | convert-chain |
lib.rs | convert-chain |
version | 0.1.3 |
source | src |
created_at | 2023-05-25 11:49:22.129588 |
updated_at | 2023-05-26 05:03:27.515074 |
description | A simple chain converter |
homepage | |
repository | https://github.com/Berberine/convert-chain |
max_upload_size | |
id | 874241 |
size | 6,068 |
convert-chain
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));