Add AsByte trait and satisfy, one_of and none_of for bytes#1789
Open
SneedSeedFeed wants to merge 2 commits intorust-bakery:mainfrom
Open
Add AsByte trait and satisfy, one_of and none_of for bytes#1789SneedSeedFeed wants to merge 2 commits intorust-bakery:mainfrom
SneedSeedFeed wants to merge 2 commits intorust-bakery:mainfrom
Conversation
… rename one) Added satisfy, one_of and none_of to bytes::complete Added satisfy, one_of and none_of to bytes::streaming Ammended test for issue rust-bakery#1118 to specify the use of character::complete::{none_of, one_of} due to additions to bytes::complete
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
satisfyfor bytes, but noticed there was only acharacterversion that I ultimately could've reused but it just rubbed me the wrong way doing so.My solution
AsBytetrait for&u8andu8satisfy,one_ofandnone_offorbytes::{streaming, complete}.character::complete::{one_of, none_of}to specify the exact function and avoid ambiguityIssues with my solution
AsBytedoesn't really do much, adding a trait with a single function and only two implementers didn't feel right but I felt parity with thecharacterversion was more important to meet the standards of existing code.AsByteoverlaps a bit withAsBytes. To avoid changing the name ofAsBytesto something likeAsByteSlice, could maybe changeAsBytetoIsByteespecially since the only two implementers are bothu8it 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.characterimplementation, the tests in the doc comments are a little ugly to cast the&[u8; N]to&[u8]characterdocs and wrote over it so I may have left some typos or uses ofcharoveru8in there.