Skip to content

Instantly share code, notes, and snippets.

@enitrat
Created August 18, 2023 14:48
Show Gist options
  • Select an option

  • Save enitrat/0072e056ef5af2f2681852ef02b67bf5 to your computer and use it in GitHub Desktop.

Select an option

Save enitrat/0072e056ef5af2f2681852ef02b67bf5 to your computer and use it in GitHub Desktop.
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