Skip to content

Commit

Permalink
[move] Fix display implementation for Move values
Browse files Browse the repository at this point in the history
  • Loading branch information
tzakian committed Feb 28, 2024
1 parent b76d61b commit 9b1b235
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions external-crates/move/crates/move-core-types/src/annotated_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use crate::{
account_address::AccountAddress,
fmt_list,
identifier::Identifier,
language_storage::{StructTag, TypeTag},
runtime_value as R, u256,
Expand Down Expand Up @@ -410,24 +409,29 @@ impl fmt::Display for MoveValue {
MoveValue::Bool(true) => write!(f, "true"),
MoveValue::Address(a) => write!(f, "{}", a.to_hex_literal()),
MoveValue::Signer(a) => write!(f, "signer({})", a.to_hex_literal()),
MoveValue::Vector(v) => fmt_list(f, "vector[", v, "]"),
MoveValue::Vector(v) => {
use DebugAsDisplay as DD;
write!(f, "vector")?;
let mut list = f.debug_list();
for val in v {
list.entry(&DD(val));
}
list.finish()
}
MoveValue::Struct(s) => fmt::Display::fmt(s, f),
}
}
}

impl fmt::Display for MoveStruct {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use DebugAsDisplay as DD;
fmt::Display::fmt(&self.type_, f)?;
fmt_list(f, " {", self.fields.iter().map(DisplayFieldBinding), "}")
}
}

struct DisplayFieldBinding<'a>(&'a (Identifier, MoveValue));

impl fmt::Display for DisplayFieldBinding<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let DisplayFieldBinding((field, value)) = self;
write!(f, "{}: {}", field, value)
write!(f, " ")?;
let mut map = f.debug_map();
for (field, value) in &self.fields {
map.entry(&DD(field), &DD(value));
}
map.finish()
}
}

0 comments on commit 9b1b235

Please sign in to comment.