tower-web
tower-web copied to clipboard
Handlers with many arguments don't work
#[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.
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).
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.
@shepmaster I agree, but I also think this should work... There isn't a reason except I probably took a shortcut somewhere.
There isn't a reason
Ah, I assumed this was ultimately a limitation of the lack of generic constants / variadic types / etc.
I would have to look again, but I worked around that in the past by having Tuple3<_, _, Tuple3<_, _, _>>