Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scales::Value data retrieval methods #53

Open
olanod opened this issue May 2, 2024 · 0 comments
Open

scales::Value data retrieval methods #53

olanod opened this issue May 2, 2024 · 0 comments

Comments

@olanod
Copy link
Member

olanod commented May 2, 2024

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, &registry);
// 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();
@olanod olanod changed the title scales::Value data access functions scales::Value data retrieval methods May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant