merge-rs

Crates.iomerge-rs
lib.rsmerge-rs
version0.4.0
sourcesrc
created_at2022-02-16 18:05:57.719349
updated_at2023-11-20 16:19:28.068904
descriptionA small library that cuts down on the amount of code required to merge two arbitrary structs into a new struct.
homepage
repositoryhttps://github.com/dhable/merge-rs
max_upload_size
id533440
size20,122
Dan Hable (dhable)

documentation

README

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

Commit count: 26

cargo fmt