Skip to main content

module_derive/
lib.rs

1//! Derive macros for the [`module`](https://github.com/threadexio/module-rs) crate.
2
3mod merge;
4
5/// Derive the `Merge` trait.
6///
7/// This macro can be used only on `struct` items.
8///
9/// Generate a `Merge` implementation for the annotated type. The generated code
10/// calls `.merge` and `.merge_ref` on each field.
11///
12/// # Field attributes
13///
14/// ## `rename`
15///
16/// * **Syntax:** `#[merge(rename = "foo")]`
17///
18/// Rename a field so it appears under a different name in the error context.
19///
20/// ## `skip`
21///
22/// * **Syntax:** `#[merge(skip)]`
23///
24/// Completely skip merging this field. This instructs the macro to not emit
25/// code for merging the field. Skipped fields retain the value of `self`.
26///
27/// ## `with`
28///
29/// * **Syntax:** `#[merge(with = path::to::custom::merge)]`
30///
31/// Use `$module::merge` and `$module::merge_ref` to merge this field instead of
32/// its own `Merge` implementation.
33///
34/// This can be used to make external types `Merge` without having to use
35/// newtypes.
36#[proc_macro_derive(Merge, attributes(merge))]
37pub fn merge(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
38    merge::merge(item)
39}