-
-
Notifications
You must be signed in to change notification settings - Fork 724
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
Allow access to the Either type #5
Comments
Adding a small note—I'm writing a generator for Twirp. It'd be pretty nice to be able to write standalone, reusable filters that accept either On an aside, is there any reasonable way to hide the (This problem, of course, would go away if Rust had anonymous sum types.) |
I believe with trait specialization, single value extractions can be just |
Ah, gotcha—thank you for clarifying! I suppose specialization would be a better solution in this case than anon. sum types. |
I do think it's probably best to change the current I have wanted at times to be able to sort of "unify" over an let path_id = warp::path::param::<u64>();
let header_id = warp::header::<u64>("x-todo-id");
path_id
.or(header_id)
.map(handle_id);
// naming is hard
fn handle_id(id: impl EitherUnify<u64>) {
// ...
} An alternative is to add some |
Yeah, that's fair. It's kinda challenging and exposing
Oh, I like that API a lot! To be clear, if a |
Oh... No, I had meant specifically when all the types in the |
I got that part! I can see how I'm sorry if I'm not making sense—I've got too many meetings that are melting my brain. |
Ah, yes, it should, since it'd work for any So, for now, I added a |
I'm not sure whether this is the right approach here, but I'm trying to do something like this: fn render<T>(template: T) -> impl warp::Reply {
match template.render() {
Ok(html) => Either::Left(warp::reply::html(html)),
Err(err) => {
error!("template rendering failed: {} (for {:#?})", err, template);
Either::Right(warp::http::StatusCode::INTERNAL_SERVER_ERROR)
}
} Since |
Another thing I just thought of, is there any reason not to just use the |
I'm encountering a similar situation; I'd be strongly in favor of either using the either crate's I've got a branch here using the either crate if you need this now, though I'd prefer warp to lean on frunk more heavily instead. |
I'm not sure this issue is the right place to mention or discuss this, but in my fairly limited experience using |
@seanmonstar would a PR to frunkify This'd essentially just change anything using |
I had initially thought that if nested enums were used such that the final type were uninhabitable, Rust could optimize the layout to not need space for all the nested tags. I was wrong. So, maybe, instead there could be something like the |
Eh....... that seems a lot grosser; I'd honestly rather wait to see language support for "first-class" anonymous sums instead. RFC1154 got closed for prioritization reasons; I might try a revival of it as my first RFC after #35121/RFC1216 lands. |
Would a PR of https://github.com/remexre/warp/tree/either-crate be accepted for 0.2, with the change to first-class enums (or Coproduct if optimized tags happen first) being pushed off to a later breaking release? |
The
Filter::or
combinator returns anEither<A, B>
type, but it currently isn't exported publicly, making it impossible to match on the variants. It does implementReply
, making the full framework function, but it's currently impossible to useor
to retrieve either A or B.Some reasons why it hasn't been exposed yet:
Either<A, B>
to instead more likeCoprod<A, Coprod<B, Never>>
. The benefit of doing this is that nestingEither<A, B>
will result in the enums getting fatter and fatter,where as the(turns out I was wrong aboutCoprod
approach makes unlimited nestedor
s still only need space for 1 variant tagCoprod
, it also grows the size).The text was updated successfully, but these errors were encountered: