-
Notifications
You must be signed in to change notification settings - Fork 315
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
Improvements to EitherOrBoth
#629
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dcea15b
improve grammar in either_or_both
joseph-gio f020a09
add `just_{left,right}` methods to `EitherOrBoth`
joseph-gio 6dc42f5
add `into_{left,right}` methods to EitherOrBoth
joseph-gio 65d0a93
add `insert_{left,right,both}` methods to `EitherOrBoth`
joseph-gio 259dcb0
add `{left,right}or_insert{_with}` methods to `EitherOrBoth`
joseph-gio a9fc412
remove some extraneous information from `EitherOrBoth::is_both`
joseph-gio 4b15974
add `as_deref{_mut}` methods to `EitherOrBoth`
joseph-gio 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
There are no files selected for viewing
This file contains 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 prefer
left_biased
, which implies the fallback behavior onRight
. So doesinto_right
->right_biased
.This
*_biased
wording is also used byrowan
, the parser library ofrust-analyzer
, in an enum like ourEitherOrBoth
but allows empty.https://docs.rs/rowan/0.15.11/rowan/enum.TokenAtOffset.html#method.left_biased
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 don't think that the
*_biased
naming convention really captures what's going on here. TheTokenAtOffset
struct does not have to perform type conversions which makes that name work -- howeverEitherOrBoth
does have to perform type conversions, so calling itbiased
doesn't really make sense to me. Theinto_*
convention communicates that this operation performs a type conversion when necessary. Also, theTokenAtOffset
struct seems too different to be comparable toEitherOrBoth
. That struct does not haveLeft
orRight
variants, just aSingle
variant that does not specify a side. Plus, as you mentioned, it has anNone
variant which drastically changes how this operation works.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.
To my intuition,
left_biased
implies that "prefer Left, but fallback to return Right if there's no Left".into_left
sounds like "we know there's a Left inside, just unwrap it" (likeinto_inner
?).But you're right, there's a conversion when
Right(_)
is encountered, andinto_left
captures this behavior.