Skip to content

What's a good pattern for fixed bits? #130

@shepmaster

Description

@shepmaster

I'm working with a chip that needs to read a byte of the form 0b0100AAAW, where the upper bits must always be 0100. What's the best route for me to ensure that those bits will always be set to that?

Right now, I'm setting them via the default as the docs say

Default values are used as-is, even if they affect bits that aren't defined within the bitfield.

However, someone could call new_with_raw_value(0) and set those upper bits to an invalid value.

I was originally looking for something vaguely of this shape:

#[bits(4..=7, fixed = 0b0100)]
_: (),

This would let me specify that a range of bits should always be a given value and wouldn't generate setters or getters.

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