-
-
Notifications
You must be signed in to change notification settings - Fork 722
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
Return unboxed filters #132
Comments
It is possible in some cases, like |
Seems to work on current stable (1.30.1) : fn hello_filter() -> impl Filter<Extract = (impl Reply), Error = Rejection> + Copy {
warp::get2()
.and(path!("hello"))
.map(|| "hello")
} I wish we had a better way to write that kind of signature though, this looks particularly noisy to me. |
Seeing as it's possible to do as the issue title says, I'm going to close. For the comment about making |
Ok my bad, in fact it doesn't work in traits but that's an other problem (impl in traits). |
Any hint why this doesn't work then ? pub fn routes<T: EndPoint>(endpoint: T, db: Db<T>) -> impl Filter<Extract = (impl Reply), Error = Rejection> + Copy {
let db = warp::any().map(move || db.clone());
let path = warp::path(T::name());
let path_index = path.and(warp::path::end());
let path_id = path
.and(warp::path::param::<u64>())
.and(warp::path::end());
let json_body = warp::body::content_length_limit(1024 * 16).and(warp::body::json());
let list = warp::get2()
.and(path_index)
.and(db.clone())
.map(list::<T>);
let create = warp::post2()
.and(path_index)
.and(json_body)
.and(db.clone())
.and_then(create::<T>);
let update = warp::put2()
.and(path_index)
.and(json_body)
.and(db.clone())
.and_then(update::<T>);
let delete = warp::delete2()
.and(path_id)
.and(db.clone())
.and_then(delete::<T>);
// Combine our endpoints, since we want requests to match any of them:
let api = list.or(create).or(update).or(delete);
api
}
fn list<T: EndPoint>(db: Db<T>) -> impl Filter<Extract = (impl Reply), Error = Rejection> + Copy {
warp::reply::json(&*db.lock().unwrap())
} This fails with:
|
What if you changed it to: fn list<T: EndPoint>(db: Db<T>) -> impl Reply {
warp::reply::json(&*db.lock().unwrap())
} |
That's what I had first, I changed it to match what was given in this "thread". But it's the same problem: fn list<T: EndPoint>(db: Db<T>) -> impl warp::Reply {
warp::reply::json(&*db.lock().unwrap())
} gives
|
Hm, it's claiming that |
Where so ? I tried |
Would it be possible to return routes without using
boxed
? For now it requireswarp::generic::Either
which is private (see #5).The text was updated successfully, but these errors were encountered: