[][src]Macro multi_eq::multi_eq_make_derive

macro_rules! multi_eq_make_derive {
    ($vis:vis, $trait_name:ident, $method_name:ident) => { ... };
}

Macro to define a derive macro for a comparison trait

(Yes, this macro generates another macro that generates code) The format of the derived trait is the same as PartialEq, but with potentially different names.

Note:

This macro can only be used in crates with the proc-macro crate type.

Parameters:

  • vis - visibility specifier of the generated derive macro
  • trait_name - name of the trait to derive
  • method_name - name of the method in the trait, also used as the name of the proc macro

Field attributes:

Note that method_name refers to the method_name parameter supplied to the macro.

  • #[method_name(cmp = "custom_comparison_method")]
    • Instead of using the derived trait's method to compare this field, use custom_comparison_method.
  • #[method_name(ignore)]
    • When doing equality checking, ignore this field.

Example:

This example is not tested
use multi_eq::*; // This global import is required for the macro to function

multi_eq_make_derive!(pub, CustomEq, custom_eq);

Derive usage example:

This example is not tested
#[derive(CustomEq)]
struct MyStruct {
  // Use `PartialEq` to compare this field
  #[custom_eq(cmp = "eq")]
  a: u32,

  // Ignore value of this field when checking equality
  #[custom_eq(ignore)]
  b: bool,
}