sharksforarms / deku

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

Assert for tuple enum #412

Open libklein opened 5 months ago

libklein commented 5 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 2 months ago

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