tower-web icon indicating copy to clipboard operation
tower-web copied to clipboard

Handlers with many arguments don't work

Open lnicola opened this issue 7 years ago • 5 comments

#[post("/test")]
fn test(&self, accept: Option<String>, connection: Option<String>, cookie: Option<String>, host: Option<String>) -> Result<String, ()> {
    Ok(String::from("hello"))
}

yields these build errors:

error[E0277]: the trait bound `tower_web::util::tuple::Join2<tower_web::extract::option::ExtractOptionFuture<tower_web::extract::Immediate<std::string::String>>, tower_web::extract::option::ExtractOptionFuture<tower_web::extract::Immediate<std::string::String>>>: tower_web::extract::ExtractFuture` is not satisfied
error[E0599]: no method named `into_inner` found for type `tower_web::util::tuple::Join3<tower_web::util::tuple::Join2<tower_web::extract::option::ExtractOptionFuture<tower_web::extract::Immediate<std::string::String>>, tower_web::extract::option::ExtractOptionFuture<tower_web::extract::Immediate<std::string::String>>>, tower_web::extract::option::ExtractOptionFuture<tower_web::extract::Immediate<std::string::String>>, tower_web::extract::option::ExtractOptionFuture<tower_web::extract::Immediate<std::string::String>>>` in the current scope
error[E0277]: the trait bound `tower_web::util::tuple::Join2<tower_web::extract::option::ExtractOptionFuture<tower_web::extract::Immediate<std::string::String>>, tower_web::extract::option::ExtractOptionFuture<tower_web::extract::Immediate<std::string::String>>>: tower_web::extract::ExtractFuture` is not satisfied

It compiles fine after removing one of the arguments.

lnicola avatar Sep 08 '18 18:09 lnicola

My opinion is that at some point, this needs to break down into a struct:

struct Foo {
    accept: Option<String>, 
    connection: Option<String>, 
    cookie: Option<String>,
    host: Option<String>,
}

#[post("/test")]
fn test(&self, foo: Foo) -> Result<String, ()> {
    Ok(String::from("hello"))
}

However, I don't know how to perform the needed connections to make all of those names map to the appropriate header / etc. (Which always seemed a touch magic to me).

shepmaster avatar Sep 14 '18 21:09 shepmaster

It would be nice if that worked, but there shouldn't be (and I didn't see one) a magic limit of three arguments per handler.

lnicola avatar Sep 14 '18 21:09 lnicola

@shepmaster I agree, but I also think this should work... There isn't a reason except I probably took a shortcut somewhere.

carllerche avatar Sep 14 '18 21:09 carllerche

There isn't a reason

Ah, I assumed this was ultimately a limitation of the lack of generic constants / variadic types / etc.

shepmaster avatar Sep 14 '18 21:09 shepmaster

I would have to look again, but I worked around that in the past by having Tuple3<_, _, Tuple3<_, _, _>>

carllerche avatar Sep 14 '18 21:09 carllerche