-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
add either extractor #1788
add either extractor #1788
Conversation
dc9d48b
to
cc056b9
Compare
#[derive(Debug, PartialEq)] | ||
pub enum Either<A, B> { | ||
/// First branch of the type | ||
A(A), |
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.
Why A
over Left
if the docs and test code use left / right terminology rather than A / B?
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.
It's because this isnt a new type (i just moved the either parts out of responder.rs), it's in my head to rename the variants in next breaking release.
Codecov Report
@@ Coverage Diff @@
## master #1788 +/- ##
==========================================
+ Coverage 53.79% 53.90% +0.11%
==========================================
Files 129 130 +1
Lines 12201 12244 +43
==========================================
+ Hits 6563 6600 +37
- Misses 5638 5644 +6
Continue to review full report at Codecov.
|
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.
lgtm
I like this extractor. The only thing I would like to improve on is avoid using another box. |
We'll leave it for now. A box is very little considering the rest of this change. One thing I'd just like an explicit thought on is the choice to return the error for A in the case of both failing. Currently the B error is never made available. The alternatives are to only show B's error or to return both errors in a tuple. |
Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>
e9471a9
to
d9b83ca
Compare
PR Type
Feature
PR Checklist
Overview
Add extractor helper using the existing
Either<A, B>
type to handle fallbacks, likeEither<Json<Login>, Form<Login>>
for example.closes #1724