You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Variant] Simplify creation of Variants from metadata and value (#7663)
# Which issue does this PR close?
- Part of #6736
# Rationale for this change
While making documentation / examples for working with `Variant` in
#7661, I found it was somewhat
awkward to make `Variant` values directly from the metadata and value.
Specifically you have to
```rust
let metadata = [0x01, 0x00, 0x00];
let value = [0x09, 0x48, 0x49];
// parse the header metadata
let metadata = VariantMetadata::try_new(&metadata).unwrap();
// and only then can you make the Variant
Variant::try_new(&metadata, &value).unwrap()
```
I would really like to be able to create `Variant `directly from
`metadata` and `value` without having to make a `VariantMetadata`
structure
# What changes are included in this PR?
This PR proposes a small change to the API so creating a Variant now
looks like:
```rust
let metadata = [0x01, 0x00, 0x00];
let value = [0x09, 0x48, 0x49];
// You can now make the Variant directly from the metadata and value
Variant::try_new(&metadata, &value).unwrap()
```
# Are there any user-facing changes?
Yes, the API for creating APIs is slightly different (and I think
better)
0 commit comments