scales::Value is a lightweight container that simply holds references to a type registry and the scale encoded data, it allows using serde to for example build a serde_json::Value from the underlying encoded data to make it easy for users to interpret it. However in constrained contexts where its not desirable to have the extra serde_json or similar dependency and allocate a new object having some utility functions on Value to access fields and values can come quite handy.
// e.g. struct that that gets encoded to scale
struct SomeStruct<'a> {
field_a: u8,
field_b: &'a str,
}
let value = Value::new(&encoded_some_struct, ty_id, ®istry);
// e.g. some way to access a field
let f_a = value.field("field_a")?.as_u8()?;
// e.g. a method that returns an iterator of (field, value)
let f_b = value.fields().filter_map(|(f, _v)| f.eq("field_b").then_some(v) )?.as_str();
scales::Value
is a lightweight container that simply holds references to a type registry and the scale encoded data, it allows using serde to for example build aserde_json::Value
from the underlying encoded data to make it easy for users to interpret it. However in constrained contexts where its not desirable to have the extra serde_json or similar dependency and allocate a new object having some utility functions onValue
to access fields and values can come quite handy.