Crates.io | struct_macro_eq |
lib.rs | struct_macro_eq |
version | 0.1.0 |
source | src |
created_at | 2023-02-20 01:55:01.608028 |
updated_at | 2023-02-20 01:55:01.608028 |
description | implements Eq for structs, but with the ability to exclude fields from equality checking using an ignore_regex attribute |
homepage | https://github.com/milselarch/struct_macro_eq/ |
repository | |
max_upload_size | |
id | 789435 |
size | 5,782 |
implements Eq for structs, but with the ability to exclude fields from equality checking using an ignore_regex attribute
Example usage:
use struct_macro_eq;
/*
tow Dish-es are implemented to be equal here if
their carbs and fats fields match (_temp is excluded
because it starts with an underscore and hence
matches ignore_regex="^_")
*/
#[derive(struct_macro_eq::CustomEq)]
#[ignore_regex="^_"]
struct Dish {
carbs: u64,
fats: u64,
_temp: u64
}
fn main() {
let dish1 = Dish { carbs: 30, fats: 20, _temp: 30 };
let dish2 = Dish { carbs: 30, fats: 20, _temp: 20 };
let dish3 = Dish { carbs: 30, fats: 10, _temp: 30 };
// dish1 and dish2 are equal
println!("dish1 == dish2: {}", dish1 == dish2);
// dish1 and dish3 are not equal
println!("dish1 == dish3: {}", dish1 == dish3);
}