#[derive(Response)] | ^^^^^^^^ use of undeclared type or module `http`
I'm unable to derive a response, yielding the error in the title.
I'm on stable (1.32.0), with edition 2018 enabled.
Sorry if this is not appropriate issue– but I'm a beginner and have spent a few hours trying to get around this issue.
Thanks for your work!
Interesting. Do you have a repro?
Here's a trivial repro case:
#[macro_use]
extern crate tower_web;
extern crate tokio;
use tower_web::ServiceBuilder;
pub fn main() {
let addr = "127.0.0.1:8080".parse().expect("Invalid address");
println!("Listening on http://{}", addr);
ServiceBuilder::new()
.resource(Routes {})
.run(&addr)
.unwrap();
}
#[derive(Clone, Debug, Response)]
pub struct Routes {}
impl_web! {
impl Routes {
#[get("/")]
fn hello_world( & self ) -> Result < String, () > {
Ok(format!("HEY BUCKO!"))
}
}
}
this works without the derive Response.
I hit this when trying to use the handlebars templating, which necessitated deriving a response (the content type and template macros did not raise any errors).
The derive response was originally on an associated struct that the methods were returning, but I removed that from the code because it didn't seem relevant.
this is using:
[package]
name = "wat"
version = "0.1.0"
edition = "2018"
[dependencies]
tokio = "^0.1.15"
tower-web = "^0.3.4"
Same error here with https://paste.ee/p/HEvPJ Also I'm hitting "unimplemented!" errors and "web is a reserved keyboard" !?
I just retried and I get the same error with your handlebars example Using
[dependencies]
tower-web="0.3"
tokio="0.1"
serde = "1.0.70"
serde_derive = "1.0.70"
serde_json = "1.0.24"
serde_plain = "0.3.0"
serde_urlencoded = "0.5.1"
error[E0433]: failed to resolve: use of undeclared type or module `http`
--> src/main.rs:23:17
|
23 | #[derive(Debug, Response)]
| ^^^^^^^^ use of undeclared type or module `http`
error: aborting due to previous error
@denniscollective @emschwartz I've fixed the compile error when adding the http crate.
So to get a) Extract and b) Response to run you need the following cargo.toml
[dependencies]
tower-web="0.3"
tokio="0.1"
serde = "1.0.70"
serde_derive = "1.0.70"
serde_json = "1.0.24"
serde_plain = "0.3.0"
serde_urlencoded = "0.5.1"
http = "0.1.7"
Edit: I still had to switch over to actix as I got unimplemented! and handlebars-not-found runtime exceptions with the examples.
Thanks! I will investigate now.
Ah, I bet edition 2018 has something to do with it...
I opened #185 to fix the http issue.
Fixing the _serde issue will require an upstream change: https://github.com/serde-rs/serde/issues/1487
As a work around for now, you may include the following dependencies in your Cargo.toml:
serde = "1"
http = "0.1"
Additionally, Rust 2018 macro imports are not supported yet. Supporting this will require a breaking change release to tower-web.
For now, using [macro_use] extern crate tower_web; works.
I'm pretty used to [macro_use] extern crate .., it's kinda the default everywhere.
Is it still normal that I get "not yet implemented" panics when trying to use extract & response with structs ?
@0xpr03 no... could you provide a backtrace?
I pushed a new version of tower-web-macros that fixes the http issue.
Ok so the last update fixed my "not yet implemented" panics. Not sure what exactly caused this.
Hm, for some reason I'm hitting that bug again. I can't seem to reproduce it with the same cargo.toml and same request structure in my clean test-setup.
thread 'tokio-runtime-worker-4' panicked at 'not yet implemented', /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tower-web-0.3.5/src/extract/serde.rs:54:17
note: Run with `RUST_BACKTRACE=1` for a backtrace.
#[post("/instance/stop")]
#[content_type("application/json")]
fn instance_stop(&self, data: InstanceStopReq) -> Fallible<DefaultResponse> {
debug!("stop request: {:?}",data);
Ok(DefaultResponse{success: true,msg: None})
}
#[derive(Debug, Clone, Extract)]
pub struct InstanceStopReq {
pub a: i32,
}
Stacktrace
stack backtrace:
0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
1: std::sys_common::backtrace::_print
at src/libstd/sys_common/backtrace.rs:71
2: std::panicking::default_hook::{{closure}}
at src/libstd/sys_common/backtrace.rs:59
at src/libstd/panicking.rs:211
3: std::panicking::default_hook
at src/libstd/panicking.rs:227
4: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:491
5: std::panicking::begin_panic
at /rustc/9fda7c2237db910e41d6a712e9a2139b352e558b/src/libstd/panicking.rs:425
6: <tower_web::extract::serde::SerdeFuture<T, B>>::new_extract
at ./<::std::macros::panic macros>:3
7: yamba_backend::models::__IMPL_EXTRACT_FOR_InstanceStopReq::<impl tower_web::extract::Extract<B> for yamba_backend::models::InstanceStopReq>::extract
at src/models.rs:88
8: <yamba_backend::api::__IMPL_WEB_0_FOR_ApiResource::__GeneratedResource<__S, __B, yamba_backend::api::ApiResource> as tower_web::routing::resource::Resource>::dispatch
at ./<::tower_web::derive_resource macros>:2
9: <tower_web::routing::service::RoutedService<T, U> as tower_service::Service>::call
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tower-web-0.3.5/src/routing/service.rs:123
10: <T as tower_web::util::http::service::HttpService>::call_http
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tower-web-0.3.5/src/util/http/service.rs:62
11: <tower_web::service::web::WebService<T, U, M> as tower_service::Service>::call
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tower-web-0.3.5/src/service/web.rs:53
12: <T as tower_web::util::http::service::HttpService>::call_http
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tower-web-0.3.5/src/util/http/service.rs:62
13: <tower_web::run::Lift<T> as hyper::service::service::Service>::call
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tower-web-0.3.5/src/run.rs:82
14: <hyper::proto::h1::dispatch::Server<S> as hyper::proto::h1::dispatch::Dispatch>::recv_msg
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.24/src/proto/h1/dispatch.rs:405
15: <hyper::proto::h1::dispatch::Dispatcher<D, Bs, I, T>>::poll_read_head
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.24/src/proto/h1/dispatch.rs:213
16: <hyper::proto::h1::dispatch::Dispatcher<D, Bs, I, T>>::poll_read
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.24/src/proto/h1/dispatch.rs:136
17: <hyper::proto::h1::dispatch::Dispatcher<D, Bs, I, T>>::poll_inner
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.24/src/proto/h1/dispatch.rs:100
18: <hyper::proto::h1::dispatch::Dispatcher<D, Bs, I, T>>::poll_catch
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.24/src/proto/h1/dispatch.rs:86
19: <hyper::proto::h1::dispatch::Dispatcher<D, Bs, I, T> as futures::future::Future>::poll
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.24/src/proto/h1/dispatch.rs:348
20: <futures::future::either::Either<A, B> as futures::future::Future>::poll
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/future/either.rs:35
21: futures::future::option::<impl futures::future::Future for core::option::Option<F>>::poll
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/future/option.rs:12
22: <hyper::server::conn::Connection<I, S, E> as futures::future::Future>::poll
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.24/src/server/conn.rs:577
23: <futures::future::map::Map<A, F> as futures::future::Future>::poll
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/future/map.rs:30
24: <futures::future::map_err::MapErr<A, F> as futures::future::Future>::poll
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/future/map_err.rs:30
25: <futures::future::chain::Chain<A, B, C>>::poll
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/future/chain.rs:32
26: <futures::future::and_then::AndThen<A, B, F> as futures::future::Future>::poll
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/future/and_then.rs:32
27: <alloc::boxed::Box<F> as futures::future::Future>::poll
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/future/mod.rs:113
28: <futures::task_impl::Spawn<T>>::poll_future_notify::{{closure}}
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/mod.rs:326
29: <futures::task_impl::Spawn<T>>::enter::{{closure}}
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/mod.rs:396
30: futures::task_impl::std::set
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/std/mod.rs:78
31: <futures::task_impl::Spawn<T>>::enter
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/mod.rs:396
32: <futures::task_impl::Spawn<T>>::poll_fn_notify
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/mod.rs:288
33: <futures::task_impl::Spawn<T>>::poll_future_notify
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/task_impl/mod.rs:326
34: tokio_threadpool::task::Task::run::{{closure}}
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.11/src/task/mod.rs:141
35: core::ops::function::FnOnce::call_once
at /rustc/9fda7c2237db910e41d6a712e9a2139b352e558b/src/libcore/ops/function.rs:238
36: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
at /rustc/9fda7c2237db910e41d6a712e9a2139b352e558b/src/libstd/panic.rs:319
37: std::panicking::try::do_call
at /rustc/9fda7c2237db910e41d6a712e9a2139b352e558b/src/libstd/panicking.rs:310
38: __rust_maybe_catch_panic
at src/libpanic_unwind/lib.rs:102
39: std::panicking::try
at /rustc/9fda7c2237db910e41d6a712e9a2139b352e558b/src/libstd/panicking.rs:289
40: std::panic::catch_unwind
at /rustc/9fda7c2237db910e41d6a712e9a2139b352e558b/src/libstd/panic.rs:398
41: tokio_threadpool::task::Task::run
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.11/src/task/mod.rs:127
42: tokio_threadpool::worker::Worker::run_task2
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.11/src/worker/mod.rs:572
43: tokio_threadpool::worker::Worker::run_task
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.11/src/worker/mod.rs:461
44: tokio_threadpool::worker::Worker::try_run_owned_task
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.11/src/worker/mod.rs:394
45: tokio_threadpool::worker::Worker::try_run_task
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.11/src/worker/mod.rs:302
46: tokio_threadpool::worker::Worker::run
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.11/src/worker/mod.rs:246
47: tokio::runtime::threadpool::builder::Builder::build::{{closure}}::{{closure}}::{{closure}}::{{closure}}
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.15/src/runtime/threadpool/builder.rs:340
48: tokio_timer::timer::handle::with_default::{{closure}}
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-timer-0.2.10/src/timer/handle.rs:94
49: <std::thread::local::LocalKey<T>>::try_with
at /rustc/9fda7c2237db910e41d6a712e9a2139b352e558b/src/libstd/thread/local.rs:309
50: <std::thread::local::LocalKey<T>>::with
at /rustc/9fda7c2237db910e41d6a712e9a2139b352e558b/src/libstd/thread/local.rs:255
51: tokio_timer::timer::handle::with_default
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-timer-0.2.10/src/timer/handle.rs:81
52: tokio::runtime::threadpool::builder::Builder::build::{{closure}}::{{closure}}::{{closure}}
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.15/src/runtime/threadpool/builder.rs:339
53: tokio_timer::clock::clock::with_default::{{closure}}
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-timer-0.2.10/src/clock/clock.rs:141
54: <std::thread::local::LocalKey<T>>::try_with
at /rustc/9fda7c2237db910e41d6a712e9a2139b352e558b/src/libstd/thread/local.rs:309
55: <std::thread::local::LocalKey<T>>::with
at /rustc/9fda7c2237db910e41d6a712e9a2139b352e558b/src/libstd/thread/local.rs:255
56: tokio_timer::clock::clock::with_default
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-timer-0.2.10/src/clock/clock.rs:124
57: tokio::runtime::threadpool::builder::Builder::build::{{closure}}::{{closure}}
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.15/src/runtime/threadpool/builder.rs:338
58: tokio_reactor::with_default::{{closure}}
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-reactor-0.1.8/src/lib.rs:229
59: <std::thread::local::LocalKey<T>>::try_with
at /rustc/9fda7c2237db910e41d6a712e9a2139b352e558b/src/libstd/thread/local.rs:309
60: <std::thread::local::LocalKey<T>>::with
at /rustc/9fda7c2237db910e41d6a712e9a2139b352e558b/src/libstd/thread/local.rs:255
61: tokio_reactor::with_default
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-reactor-0.1.8/src/lib.rs:212
62: tokio::runtime::threadpool::builder::Builder::build::{{closure}}
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.15/src/runtime/threadpool/builder.rs:337
63: tokio_threadpool::callback::Callback::call
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.11/src/callback.rs:21
64: tokio_threadpool::worker::Worker::do_run::{{closure}}::{{closure}}
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.11/src/worker/mod.rs:132
65: tokio_executor::global::with_default::{{closure}}
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-executor-0.1.6/src/global.rs:192
66: <std::thread::local::LocalKey<T>>::try_with
at /rustc/9fda7c2237db910e41d6a712e9a2139b352e558b/src/libstd/thread/local.rs:309
67: <std::thread::local::LocalKey<T>>::with
at /rustc/9fda7c2237db910e41d6a712e9a2139b352e558b/src/libstd/thread/local.rs:255
68: tokio_executor::global::with_default
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-executor-0.1.6/src/global.rs:162
69: tokio_threadpool::worker::Worker::do_run::{{closure}}
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.11/src/worker/mod.rs:130
70: <std::thread::local::LocalKey<T>>::try_with
at /rustc/9fda7c2237db910e41d6a712e9a2139b352e558b/src/libstd/thread/local.rs:309
71: <std::thread::local::LocalKey<T>>::with
at /rustc/9fda7c2237db910e41d6a712e9a2139b352e558b/src/libstd/thread/local.rs:255
72: tokio_threadpool::worker::Worker::do_run
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.11/src/worker/mod.rs:121
73: tokio_threadpool::pool::Pool::spawn_thread::{{closure}}
at /home/aron/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.11/src/pool/mod.rs:346
Edit: Giving up after 2h of investigation. Will look at this again tomorrow.
Ok I've found the error: Don't name "body" anything else than "body":
#[post("/instance/stop")]
#[content_type("application/json")]
fn instance_stop(&self, body: InstanceStopReq) -> Fallible<DefaultResponse> {
debug!("stop request: {:?}",body);
Ok(DefaultResponse{success: true,msg: None})
}
This works, exactly due to body instead of data or anything else. Otherwise tower-web will throw around "not yet implemented" errors.. This took me way more time than it should. Yes the docs state you should call it "body", still I didn't find that bug until looking into it for some hours.
Sorry for hijacking the issue. Unrelated to the dependency problem.
That isn't a good error for sure.
body is the way tower-web knows to extract the data from the HTTP body. Eventually, i would add an attribute to allow renaming, but for now it is only via var names.
In hindsight it makes totally sense, but the error message and the fact that you normally can rename anything led me to trying around, believing I still have a serde dependency problem.