Skip to content
Snippets Groups Projects

Replace manual bit flags with auto-generated bit flag construct

Merged Michael Aaron Murphy requested to merge huntergoldstein:bitflags into master

Created by: huntergoldstein

Problem: There are small ergonomics issues with using hand-rolled bit flags as described in #308 (closed).

Solution: Replace the use of the hand-rolled flags with auto-generated bitflags structures that provide nice mnemonics for membership while being mostly compatible with the old syntax.

Changes introduced by this pull request:

  • Bitflags have been replaced with bitflag! equivalents as per the bitflag crate

Drawbacks:

  • I'm not entirely sure if this is any more readable than before: part of the problem is contains versus intersects, where foo.contains(bar) is foo & bar == bar and foo.intersects(bar) is foo & bar != 0. These names are non-intuitive.
  • In addition to the above, the operators tended to be much more concise so for the most part I tried to not replace them with the mnemonics.
  • There is a slight chance that this is overall less efficient (more function calls) but I highly doubt it; the bitflags crate essentially has #[inline] on every function

Fixes: Closes #308 (closed).

State: I'm on the fence on whether or not this is a worthwhile addition, but I have nothing else to add.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
Please register or sign in to reply
Loading