Skip to content

Commit

Permalink
visitor: Expose layout for values via driver
Browse files Browse the repository at this point in the history
## Description
Initialise `ValueDriver` with a layout so that visitor functions can
query the layout in all cases (not just for structs, vectors and enums).

## Test plan

```
move-core-types$ cargo nextest run
sui-types$ cargo nextest run
```
  • Loading branch information
amnn committed Sep 25, 2024
1 parent 1da6a61 commit a7fc2dc
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 89 deletions.
2 changes: 1 addition & 1 deletion crates/sui-types/src/object/balance_traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'b, 'l> Traversal<'b, 'l> for Accumulator {
type Error = annotated_visitor::Error;
fn traverse_u64(
&mut self,
_driver: &ValueDriver<'_, 'b>,
_driver: &ValueDriver<'_, 'b, 'l>,
value: u64,
) -> Result<(), Self::Error> {
self.total += value;
Expand Down
18 changes: 9 additions & 9 deletions crates/sui-types/src/object/bounded_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,71 +152,71 @@ impl<'b, 'l> Visitor<'b, 'l> for BoundedVisitor {

fn visit_u8(
&mut self,
_driver: &ValueDriver<'_, 'b>,
_driver: &ValueDriver<'_, 'b, 'l>,
value: u8,
) -> Result<Self::Value, Self::Error> {
Ok(A::MoveValue::U8(value))
}

fn visit_u16(
&mut self,
_driver: &ValueDriver<'_, 'b>,
_driver: &ValueDriver<'_, 'b, 'l>,
value: u16,
) -> Result<Self::Value, Self::Error> {
Ok(A::MoveValue::U16(value))
}

fn visit_u32(
&mut self,
_driver: &ValueDriver<'_, 'b>,
_driver: &ValueDriver<'_, 'b, 'l>,
value: u32,
) -> Result<Self::Value, Self::Error> {
Ok(A::MoveValue::U32(value))
}

fn visit_u64(
&mut self,
_driver: &ValueDriver<'_, 'b>,
_driver: &ValueDriver<'_, 'b, 'l>,
value: u64,
) -> Result<Self::Value, Self::Error> {
Ok(A::MoveValue::U64(value))
}

fn visit_u128(
&mut self,
_driver: &ValueDriver<'_, 'b>,
_driver: &ValueDriver<'_, 'b, 'l>,
value: u128,
) -> Result<Self::Value, Self::Error> {
Ok(A::MoveValue::U128(value))
}

fn visit_u256(
&mut self,
_driver: &ValueDriver<'_, 'b>,
_driver: &ValueDriver<'_, 'b, 'l>,
value: U256,
) -> Result<Self::Value, Self::Error> {
Ok(A::MoveValue::U256(value))
}

fn visit_bool(
&mut self,
_driver: &ValueDriver<'_, 'b>,
_driver: &ValueDriver<'_, 'b, 'l>,
value: bool,
) -> Result<Self::Value, Self::Error> {
Ok(A::MoveValue::Bool(value))
}

fn visit_address(
&mut self,
_driver: &ValueDriver<'_, 'b>,
_driver: &ValueDriver<'_, 'b, 'l>,
value: AccountAddress,
) -> Result<Self::Value, Self::Error> {
Ok(A::MoveValue::Address(value))
}

fn visit_signer(
&mut self,
_driver: &ValueDriver<'_, 'b>,
_driver: &ValueDriver<'_, 'b, 'l>,
value: AccountAddress,
) -> Result<Self::Value, Self::Error> {
Ok(A::MoveValue::Signer(value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl MoveStruct {
V::Error: std::error::Error + Send + Sync + 'static,
{
let mut bytes = Cursor::new(blob);
let driver = ValueDriver::new(&mut bytes);
let driver = ValueDriver::new(&mut bytes, None);
let res = visit_struct(driver, ty, visitor)?;
if bytes.position() as usize == blob.len() {
Ok(res)
Expand Down
Loading

0 comments on commit a7fc2dc

Please sign in to comment.