Skip to content

Instantly share code, notes, and snippets.

@DavideSilva
Created March 14, 2023 11:11
Show Gist options
  • Save DavideSilva/b32d529f6dde1b60e637dee56050524b to your computer and use it in GitHub Desktop.
Save DavideSilva/b32d529f6dde1b60e637dee56050524b to your computer and use it in GitHub Desktop.
#[derive(Copy, Drop)]
struct MyStruct {
val: felt,
}
trait MyTrait<T> {
fn is_green(self: @T) -> bool;
}
impl RGBImpl of MyTrait::<MyStruct> {
fn is_green(self: @MyStruct) -> bool {
*self.val == 1
}
}
#[test]
fn assert_is_green() {
let green = MyStruct {val: 1};
assert(green.is_green(), 'not green'); // <- This gives compiler error "Method `is_green` not found on type
assert((@green).is_green(), 'not green'); // <- This works
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment