Skip to content

Commit

Permalink
docs: Add to OOP example
Browse files Browse the repository at this point in the history
  • Loading branch information
Sword-Smith committed Aug 24, 2024
1 parent 5cb3abb commit 701c73e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,26 @@ example, the program must be initialized with an encoded structure `TestStructur
struct TestStruct {
a: BFieldElement,
b: BFieldElement,
c: u32,
d: u64,
}

impl TestStruct {
fn ab_sum(&self) -> BFieldElement {
return self.a + self.b;
}

fn cd_sum(&self, other_value: u64) -> u128 {
return self.c as u128 + self.d as u128 + other_value as u128;
}
}

fn main() {
let test_struct: Box<TestStruct> =
TestStruct::decode(&tasm::load_from_memory(BFieldElement::new(0))).unwrap();
TestStruct::decode(&tasm::load_from_memory(BFieldElement::new(2))).unwrap();
let other_value: u64 = 2023;
tasm::tasmlib_io_write_to_stdout___bfe(test_struct.ab_sum());
tasm::tasmlib_io_write_to_stdout___u128(test_struct.cd_sum(other_value));
return;
}
```
Expand Down

0 comments on commit 701c73e

Please sign in to comment.