sharksforarms / deku

Declarative binary reading and writing: bit-level, symmetric, serialization/deserialization
Apache License 2.0
1.14k stars 55 forks source link

Assert for tuple enum #412

Closed libklein closed 1 month ago

libklein commented 10 months ago

I am wondering whether it is possible to define assertions over (anonymous) tuple structs, as in the following example:

#[derive(DekuRead, DekuWrite)]
#[deku(type = "u8", bits = "1")]
pub enum RegisterOrValue {
    #[deku(id = "0b0")]
    Field(#[deku(assert = "*??? < 32")] u8),
}

Is there some deku internal name that could be used to reference the parsed u8?

sharksforarms commented 6 months ago

Try the following: #[deku(assert = "*field_0 < 32")] u8

wcampbell0x2a commented 1 month ago

Closing, unless this didn't work for you!