Skip to content

temp and assert_eq #584

@carlocorradini

Description

@carlocorradini

Allow temp to be combined with assert_eq.
If both attributes are combined, a build error is generated because the field cannot be found in the scope.

#[deku_derive(DekuRead, DekuWrite)]
pub struct Packet {
    #[deku(temp, temp_value = "Self::SIZE", assert_eq = "Self::SIZE")]
    size: u16,
    // ...
}

impl Packet {
    const SIZE: u16 = 128;
}

In this scenario, the packet size is known, hence there is no need for a field in the final struct. However, when reading, I want to ensure that the temporary size matches my known value. When writing, keep the same known value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions