#merge #struct #amount #required #down #left #cuts

merge-rs

A small library that cuts down on the amount of code required to merge two arbitrary structs into a new struct

4 releases (breaking)

0.4.0 Nov 20, 2023
0.3.0 Apr 21, 2023
0.2.0 Oct 27, 2022
0.1.2 Feb 16, 2022

#4 in #left

39 downloads per month

MIT license

9KB
127 lines

merge-rs

A small library that cuts down on the amount of code required to merge two arbitrary structs into a new struct.

Documentation

[dependencies]
merge-rs = "0.4"

Example

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:?}")
}

Contributors

Dependencies

~1.5MB
~41K SLoC