Crate just_convert
source ·Expand description
just-convert make easier to convert between structs.
This crate provides JustConvert derive macro.
Example of use:
// Allow convert A struct into B struct
#[derive(JustConvert)]
#[convert(into(B))]
struct A {
// field can be renamed
#[convert(rename = bid)]
id: i64,
// field can execute any expression
#[convert(map = ".to_string()")]
num: i64,
// unwrap Option value for B::name
#[convert(unwrap)]
name: Option<String>,
}
struct B {
bid: i64,
num: String,
name: String,
}
See more examples