Created
August 18, 2023 14:48
-
-
Save enitrat/0072e056ef5af2f2681852ef02b67bf5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| use box::BoxTrait; | |
| #[derive(Drop)] | |
| struct MyStruct { | |
| a: Box<InnerStruct>, | |
| b: felt252, | |
| c: felt252 | |
| } | |
| #[derive(Copy, Drop)] | |
| struct InnerStruct { | |
| x: felt252, | |
| y: felt252, | |
| z: felt252 | |
| } | |
| #[generate_trait] | |
| impl MyStructImpl of MyStructTrait { | |
| #[inline(always)] | |
| fn get_x(self: @MyStruct) -> felt252 { | |
| let inner = (*self.a).unbox(); | |
| inner.x | |
| } | |
| } | |
| fn main() -> MyStruct { | |
| let my_struct = MyStruct { a: BoxTrait::new(InnerStruct { x: 1, y: 2, z: 3 }), b: 4, c: 5 }; | |
| my_struct.get_x(); | |
| my_struct | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment