Created
March 3, 2023 19:52
-
-
Save DavideSilva/e0f646ee8a9392888356ae2c896f5766 to your computer and use it in GitHub Desktop.
custom struct comparison in Cairo 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[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