Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR replaces the bitflags functionality with an in-house implementation.
I think we all agree on reducing the number of dependencies where it makes sense, and I also think bitflags is one dependency worth removing. It is based on a
macro_rule
which is able to escape the original Rust syntax (think of that: u8
syntax to specify that flags are bytes. That's a C++ notation!), making code a little confusing.macro_rules
have too much freedom of toying with the code, IMO.The new
Flags
struct is a type-safe and value-safe collection of flags. It is not possible to build an invalid collection of Flags. The idea is based onstd::fs::OpenOptions
.Did you note that
bits()
private method? That's a micro-optimization. While I could implement thecontains()
method using pure boolean logic, with Compiler Explorer I noticed that that would introduce conditional jumps in the assembly. For the sake of the CPU pipeline, I chose to convert the single flags back into an integer for the comparison, thus avoiding jumps altogether.