Skip to content

Instantly share code, notes, and snippets.

@DavideSilva
Created March 3, 2023 19:52
Show Gist options
  • Save DavideSilva/e0f646ee8a9392888356ae2c896f5766 to your computer and use it in GitHub Desktop.
Save DavideSilva/e0f646ee8a9392888356ae2c896f5766 to your computer and use it in GitHub Desktop.
custom struct comparison in Cairo 1
#[derive(Drop)]
struct MyStruct {
first_attribute: u8,
second_attribute: u8,
}
impl MyStructPartialEq of PartialEq::<@MyStruct> {
fn eq(a: @MyStruct, b: @MyStruct) -> bool {
*a.first_attribute == *b.first_attribute & *a.second_attribute == *b.second_attribute
}
fn ne(a: @MyStruct, b: @MyStruct) -> bool {
!(*a.first_attribute == *b.first_attribute & *a.second_attribute == *b.second_attribute)
}
}
#[test]
fn test_struct_comparison() {
let struct1 = @MyStruct { first_attribute: 0_u8, second_attribute: 1_u8 };
let struct2 = @MyStruct { first_attribute: 0_u8, second_attribute: 1_u8 };
assert(struct1 == struct2, 'structs are different');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment