Crates.io | merge-rs-derive |
lib.rs | merge-rs-derive |
version | 0.4.0 |
source | src |
created_at | 2023-11-20 16:19:14.119973 |
updated_at | 2023-11-20 16:19:14.119973 |
description | A small library that cuts down on the amount of code required to merge two arbitrary structs into a new struct. |
homepage | |
repository | https://github.com/dhable/merge-rs |
max_upload_size | |
id | 1042489 |
size | 6,354 |
A small library that cuts down on the amount of code required to merge two arbitrary structs into a new struct.
[dependencies]
merge-rs = "0.4"
fn special_concat(left: &str, right: &String) -> Result<String, Box<Error>> {
Ok(format!("{left}_{right}"))
}
#[derive(Debug, Merge)]
struct MyType {
#[merge_field(skip)]
transient_field: usize,
#[merge_field(strategy = "special_concat")]
label: String
}
fn main() {
let first = MyType { transient_field: 123, label: "first".to_owned() };
let second = MyType { transient_field: 456, label: "second".to_owned() };
let merged = first.merge(&second).unwrap();
println!("{merged:?}")
}