-
Notifications
You must be signed in to change notification settings - Fork 1.6k
RFC: Needle API (née Pattern API) #2500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d53f3a1
Pattern API v3.0, first draft.
kennytm d0782c8
Add shallow cloning to unresolved questions.
kennytm e10b004
Merge Searcher and Consumer.
kennytm 5f00210
Fix typos and addressed some review comments.
kennytm 370bd60
Make Hay and Haystack unsafe.
kennytm eba46df
Split Searcher and Consumer again.
kennytm 58741a8
s/Pattern/Needle/g
kennytm 07308d4
Explain ReverseSearcher and DoubleEndedSearcher.
kennytm 7b0f0c3
Fixed typo.
kennytm e69b245
RFC 2500
Centril File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix typos and addressed some review comments.
- Loading branch information
commit 5f00210403c959073da1344f7e55fe394288c09d
There are no files selected for viewing
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that, due to its unsafe methods being called from safe code (e.g. in trim_start),
Haystack
needs to be anunsafe trait
. Otherwise, without ever writing an unsafe block and therefore promising to uphold the invariants of safe code, an invalid implementation ofHaystack
could violate memory safety. The fact thatsplit_around
andsplit_unchecked
are unsafe capture the fact that the caller, to preserve memory safety, must pass in valid indices, but it does nothing to prevent the callee from doing arbitrary bad behaviour even if the indices are valid.Hay
probably also needs to be anunsafe trait
. It looks like in practice,Searcher
s are implemented for specificHay
types, indicating trust of just those implementations, and , so it may not be strictly necessary. Additionally, one of the requirements of a validHaystack
implementation could be the validity of the associatedHay
type. However, with the proposedimpl<'a, H: Hay> Haystack for &'a H
, this is impossible to promise, and I think it would be necessary forHay
to be anunsafe trait
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, both are now unsafe.