https://github.com/bd103/mergeme
A derivable trait that assists with merging data together
https://github.com/bd103/mergeme
Last synced: 22 days ago
JSON representation
A derivable trait that assists with merging data together
- Host: GitHub
- URL: https://github.com/bd103/mergeme
- Owner: BD103
- Created: 2025-05-01T21:40:09.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2025-05-01T22:01:36.000Z (about 1 month ago)
- Last Synced: 2025-05-01T23:19:05.251Z (about 1 month ago)
- Language: Rust
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Merge Me!
A derivable trait that assists with merging data together.
This crate provides the `Merge` trait and derive macro. The trait is a simple interface for combining data together, while the derive macro lets you easily implement this trait for any struct.
## Installation
You can install `mergeme` with `cargo add`:
```sh
cargo add mergeme
```If you do not need `#[derive(Merge)]` and wish to avoid depending on `syn`, you may disable the default features:
```sh
cargo add mergeme --no-default-features
```Once you have installed `mergeme`, be sure to [read the documentation](https://docs.rs/mergeme) for both the trait and the derive macro. Their interfaces are simple and their docs are extensive!
## Merging in Action
```rust
use mergeme::Merge;#[derive(Merge)]
#[partial(PartialPerson)]
struct Person {
name: String,
age: u16,
#[strategy(merge)]
friends: Vec,
}let person = Person {
name: "Janette".to_string(),
age: 19,
friends: vec!["Lou".to_string()],
};// Change Janette's age to be 25 and add a friend, but preserve her original name.
let partial = PartialPerson {
name: None,
age: Some(25),
friends: Some(vec!["Kylie".to_string()]),
};let merged = person.merge(partial);
assert_eq!(merged.name, "Janette");
assert_eq!(merged.age, 25);
assert_eq!(merged.friends, ["Lou", "Kylie"]);
```## License
`mergme` is licensed under either of
* Apache License, Version 2.0 ([LICENSE-APACHE](./LICENSE-APACHE) or )
* MIT license ([LICENSE-MIT](./LICENSE-MIT) or )at your option.
## Contributing
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.