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

Consider removal of warp::ext::set #222

Closed
seanmonstar opened this issue May 9, 2019 · 5 comments · Fixed by #341
Closed

Consider removal of warp::ext::set #222

seanmonstar opened this issue May 9, 2019 · 5 comments · Fixed by #341
Milestone

Comments

@seanmonstar
Copy link
Owner

@seanmonstar seanmonstar commented May 9, 2019

It takes advantage of warp's usage of thread-local storage, but that means we can't change away from internally using TLS as long as this function requires it.

@seanmonstar seanmonstar added this to the 0.2 milestone May 9, 2019
@remexre
Copy link
Contributor

@remexre remexre commented May 9, 2019

What would the replacement API look like?

@seanmonstar
Copy link
Owner Author

@seanmonstar seanmonstar commented May 9, 2019

I'm not certain. Perhaps by adding a way to turn a Filter into a Service, extensions could be set before reaching the filters. Or a new warp::ext::with_mut(impl Fn(&mut Extensions)) could be added.

@carllerche
Copy link

@carllerche carllerche commented May 10, 2019

Makes sense 👍

@itsfarseen
Copy link

@itsfarseen itsfarseen commented Apr 21, 2021

How to set an extension in latest version of warp?
I was trying to pass db pool to my routes.

@paulzhang5511
Copy link

@paulzhang5511 paulzhang5511 commented Apr 22, 2021

@itsfarseen

fn with_db(pool: Pool) -> impl Filter<Extract = (Pool,), Error = Infallible> + Clone {
    warp::any().map(move || pool.clone())
}

let user_create = warp::path!("api" / "user" / "create")
        .and(warp::post())
        .and(warp::body::json())
        .and(with_db(pool.clone()))
        .and_then(user::user_create);

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 a pull request may close this issue.

5 participants