Skip to content

Introduce FromZeroes trait#143

Merged
joshlf merged 1 commit intomainfrom
from-zeroes
Nov 15, 2022
Merged

Introduce FromZeroes trait#143
joshlf merged 1 commit intomainfrom
from-zeroes

Conversation

@joshlf
Copy link
Member

@joshlf joshlf commented Nov 11, 2022

Closes #30

@joshlf joshlf linked an issue Nov 11, 2022 that may be closed by this pull request
@joshlf joshlf force-pushed the from-zeroes branch 4 times, most recently from 41a3827 to afa6be1 Compare November 12, 2022 02:59
@joshlf
Copy link
Member Author

joshlf commented Nov 12, 2022

@djkoloski ready for a review when you get a chance!

This is enabled by three core marker traits, each of which can be derived
This is enabled by four core marker traits, each of which can be derived
(e.g., `#[derive(FromBytes)]`):
- `FromZeroes` indicates that a sequence of zero bytes represents a valid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wording is a little awkward, it could be interpreted as a sequence of length 0. Maybe something like "FromZeroes indicates that a sequence of bytes all set to zero represents a valid instance of a type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call; I've updated it, but kept the "Types..." prefix to be consistent with other traits. I can change all of them if you'd prefer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed change? I don't see this in the latest revision.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

// An enum is `FromZeroes` if:
// - Every possible bit pattern must be valid, which means that every bit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this comment need fixup? Or is this just a stricter guarantee for now until we go back and fix it up?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latter - right now, this is just a copy-paste from the comment on the FromBytes derive.

@joshlf joshlf merged commit c597b7c into main Nov 15, 2022
@joshlf joshlf deleted the from-zeroes branch November 15, 2022 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Relax requirements for deriving FromZeroes on enums

2 participants