Skip to content

Auto-forward Order-typed ctx parameter as bit_order - #660

Merged
wcampbell0x2a merged 4 commits into
sharksforarms:masterfrom
sachaw:master
Aug 30, 2026
Merged

Auto-forward Order-typed ctx parameter as bit_order#660
wcampbell0x2a merged 4 commits into
sharksforarms:masterfrom
sachaw:master

Conversation

@sachaw

@sachaw sachaw commented May 12, 2026

Copy link
Copy Markdown
Contributor

Hi, I hit the following issue in one of my projects.
When a nested struct/enum receives bit ordering via ctx = "o: Order", it currently has to also set bit_order = "o" for that order to be applied — otherwise the ctx parameter is silently ignored and codegen falls back to msb.
#602 hit this and was closed pointing to that duplicate-attribute workaround; this PR forwards an Order-typed ctx parameter as the runtime bit_order automatically when no explicit bit_order is given.

Repro (against 0.20.3)

use deku::prelude::*;

#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
#[deku(bit_order = "lsb")]
struct Parent { left: Child, right: Child }

#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
#[repr(u8)]
#[deku(bits = 4, id_type = "u8",
       ctx = "_o: deku::ctx::Order",
       ctx_default = "deku::ctx::Order::Lsb0")]
enum Child { Empty = 0x0, Full = 0xf }

#[test]
fn lsb_propagates_from_ctx() {
    let v = Parent::try_from([0xf0].as_ref()).unwrap();
    assert_eq!(v, Parent { left: Child::Full, right: Child::Empty });
    // actual on master: Parent { right: Full, left: Empty } (msb read)
}

@amboar

amboar commented May 13, 2026

Copy link
Copy Markdown
Contributor

Not really a comment of substance, but:

struct Parent { right: Child, left: Child }

it seems like an odd choice to put the variable called right on the left, and left on the right

@sachaw

sachaw commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

lol, good catch.

@sachaw

sachaw commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

hey, any change I get get this merged, I have some other PR's to file afterwards.

@wcampbell0x2a wcampbell0x2a left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fmt

@sachaw
sachaw requested a review from wcampbell0x2a August 12, 2026 02:37
@wcampbell0x2a
wcampbell0x2a merged commit a3bf8ae into sharksforarms:master Aug 30, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants