Skip to content

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

Open
sachaw wants to merge 2 commits into
sharksforarms:masterfrom
sachaw:master
Open

Auto-forward Order-typed ctx parameter as bit_order#660
sachaw wants to merge 2 commits into
sharksforarms:masterfrom
sachaw:master

Conversation

@sachaw

@sachaw sachaw commented May 12, 2026

Copy link
Copy Markdown

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
Author

lol, good catch.

@sachaw

sachaw commented Jun 17, 2026

Copy link
Copy Markdown
Author

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

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