How to Pass Extended Context to Nested Structs? #650
Unanswered
DidingasLushis
asked this question in
Q&A
Replies: 1 comment
-
|
I think my confusion may be that enums with id = "header.id()" do not inherit context? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to create a nested struct hierarchy where a child struct needs additional context parameters beyond what its parent struct receives. Specifically, I want to pass both the inherited
endiancontext AND a reference to a sibling field (field_a2: &u8) to fields (structs).Error: Type mismatch - error[E0308]: mismatched types
--> src/frame/data_a.rs:13:18
|
13 | #[deku(ctx = "(endian , field_a2)")]
| ^^^^^^^^^^^^^^^^^^^^^ expected
&u8, found(Endian, &u8)Questions
Is there a way to extend/augment the context when passing it to nested fields?
(endian)(endian, field_a2: &u8)What's the correct syntax for passing references to sibling fields as context to nested structs?
Should I restructure my data model to avoid this pattern, or is there a Deku idiom I'm missing?
Desired Behavior
When reading from bytes:
field_a1andfield_a2inDataAendianAND a reference to the just-readfield_a2value toHandlesDataHandlesDatausesfield_a2in its dynamic count calculation:count = "num_handles + *field_a2"Environment
Additional Context
This pattern is needed because:
#[cfg(feature = "feature_handles")])field_a2)Is there a recommended pattern for this in Deku?
Beta Was this translation helpful? Give feedback.
All reactions