Skip to content
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 wrap_fn #693

Merged
merged 1 commit into from
Aug 24, 2020
Merged

Add wrap_fn #693

merged 1 commit into from
Aug 24, 2020

Conversation

jxs
Copy link
Collaborator

@jxs jxs commented Aug 20, 2020

No description provided.

@jxs jxs mentioned this pull request Aug 20, 2020
@jxs jxs requested a review from seanmonstar August 20, 2020 22:28
@apiraino
Copy link

hey @jxs this PR looks really interesting!

I've loosely followed the referenced issue, I'm especially interested in the use case underlined by this comment, i.e. having the capability of making multi-step filters easier to write and follow.

How could this patch help in that regard? I can try hacking something when this PR gets merged, but I would love a more explicit (perhaps real world) example of usage.

Thanks!

@jxs jxs merged commit ec6d1ab into seanmonstar:master Aug 24, 2020
@jxs
Copy link
Collaborator Author

jxs commented Aug 24, 2020

@apiraino i am going to merge this so as it becomes available and the issue can be closed, but the example can always be improved after as we discussed in discord

@apiraino
Copy link

yes please! 👍 I didn't mean to block the merge, I'll try figuring that out as my time allows (couldnt make a good example quickly)

128f pushed a commit to 128f/warp that referenced this pull request Aug 26, 2020
@cutsoy
Copy link

cutsoy commented Nov 7, 2020

Is there a good way to represent these Wraps as return types for functions. For example:

pub fn my_custom_wrapper<F>() -> impl warp::Wrap<F>
where
    F: Filter,
    F::Extract: ...,
{
    warp::wrap_fn(|filter| ...)
}

To be used with:

warp::path(...).with(my_custom_wrapper())

This currently isn't possible yet due to the fact that Wrap is still sealed. Is there any other opaque type that can be returned?

@jxs jxs deleted the add-wrap-fn branch November 7, 2020 11:12
@jxs
Copy link
Collaborator Author

jxs commented Nov 7, 2020

@cutsoy it should be

fn my_custom_wrapper<F, T>(
    filter: F,
) -> impl Filter<Extract = (&'static str,)> + Clone + Send + Sync + 'static
where
    F: Filter<Extract = (T,), Error = std::convert::Infallible> + Clone + Send + Sync + 'static,
    F::Extract: warp::Reply,
{
...
}

warp::path(...).with(wrap_fn(my_custom_wrapper()))

take a look at the wrapping example for more details

jxs added a commit to jxs/warp that referenced this pull request Jun 27, 2021
@aujxn aujxn mentioned this pull request Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants