Add AsByte trait and satisfy, one_of and none_of for bytes #1789
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.
I just wish to preface: This is my first attempt at an open source contribution so apologies if I get things wrong, please assume ignorance or stupidity for any mistakes instead of malice.
The problem
I was writing a parser and wanted
satisfy
for bytes, but noticed there was only acharacter
version that I ultimately could've reused but it just rubbed me the wrong way doing so.My solution
AsByte
trait for&u8
andu8
satisfy
,one_of
andnone_of
forbytes::{streaming, complete}
.character::complete::{one_of, none_of}
to specify the exact function and avoid ambiguityIssues with my solution
AsByte
doesn't really do much, adding a trait with a single function and only two implementers didn't feel right but I felt parity with thecharacter
version was more important to meet the standards of existing code.AsByte
overlaps a bit withAsBytes
. To avoid changing the name ofAsBytes
to something likeAsByteSlice
, could maybe changeAsByte
toIsByte
especially since the only two implementers are bothu8
it would be arguably more descriptive.pub use characters::_::{satisfy, one_of, none_of}
to the respective module inbytes
, with the benefit of providing slightly less code to maintain.character
implementation, the tests in the doc comments are a little ugly to cast the&[u8; N]
to&[u8]
character
docs and wrote over it so I may have left some typos or uses ofchar
overu8
in there.