Skip to content

Commit

Permalink
feat: exposes necessary methods on heap newtype
Browse files Browse the repository at this point in the history
  • Loading branch information
montekki committed Jun 5, 2024
1 parent 8d29257 commit aa4068d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ u256 = { package = "primitive-types", version = "0.12.1" }
enum_dispatch = "0.3"
arbitrary = { version = "1", features = ["derive"], optional = true }
zk_evm = { git = "https://github.com/matter-labs/era-zk_evm.git", branch = "v1.5.0", optional = true }
anyhow = { optional = true }
anyhow = { version = "1", optional = true }

[dev-dependencies]
divan = "0.1"
Expand Down
24 changes: 24 additions & 0 deletions src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,30 @@ impl HeapId {
#[derive(Debug, Clone, PartialEq)]
pub struct Heap(Vec<u8>);

impl Heap {
pub fn resize(&mut self, new_len: usize, value: u8) {
self.0.resize(new_len, value);
}

pub fn len(&self) -> usize {
self.0.len()
}
}

impl<Idx: std::slice::SliceIndex<[u8]>> std::ops::Index<Idx> for Heap {
type Output = Idx::Output;

fn index(&self, i: Idx) -> &Self::Output {
self.0.index(i)
}
}

impl<Idx: std::slice::SliceIndex<[u8]>> std::ops::IndexMut<Idx> for Heap {
fn index_mut(&mut self, i: Idx) -> &mut Self::Output {
self.0.index_mut(i)
}
}

impl HeapInterface for Heap {
fn read_u256(&self, start_address: u32) -> U256 {
self.read_u256_partially(start_address..start_address + 32)
Expand Down

0 comments on commit aa4068d

Please sign in to comment.