Hi folks,
I've dug and researched and read but I just don't understand what is going wrong here.
I'm afraid I just can't make sense of how to resolve this would someone mind helping me out please?
Here is the error:
ubuntu@ubuntu:~/$ cargo run
Compiling warp-postgres-example v0.1.0 (/home/ubuntu/)
error[E0277]: the trait bound `for<'de> &std::collections::HashMap<std::string::String, std::string::String>: serde::de::Deserialize<'de>` is not satisfied
--> src/main.rs:18:18
|
18 | .and(warp::body::form())
| ^^^^^^^^^^^^^^^^ the trait `for<'de> serde::de::Deserialize<'de>` is not implemented for `&std::collections::HashMap<std::string::String, std::string::String>`
|
::: /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/warp-0.2.5/src/filters/body.rs:208:16
|
208 | pub fn form<T: DeserializeOwned + Send>() -> impl Filter<Extract = (T,), Error = Rejection> + Copy {
| ---------------- required by this bound in `warp::body::form`
|
= help: the following implementations were found:
<std::collections::HashMap<K, V, S> as serde::de::Deserialize<'de>>
= note: required because of the requirements on the impl of `serde::de::DeserializeOwned` for `&std::collections::HashMap<std::string::String, std::string::String>`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
error: could not compile `warp-postgres-example`.
To learn more, run the command again with --verbose.
ubuntu@ubuntu:~/$
Here is the code:
use warp::{self, http, Filter, Rejection, Reply};
use std::collections::HashMap;
type Result<T> = std::result::Result<T, Rejection>;
pub async fn test_route_form_handler(
form: &HashMap<String, String>,
) -> Result<impl Reply> {
let json = warp::reply::json(&vec![1]);
Ok(warp::reply::with_status(json, http::StatusCode::UNAUTHORIZED))
}
#[tokio::main]
async fn main() {
let test_route_form =
warp::path("q")
.and(warp::post())
.and(warp::body::form())
.and_then(test_route_form_handler);
let routes = test_route_form
.with(warp::cors().allow_any_origin());
warp::serve(routes).run(([127, 0, 0, 1], 8001)).await;
}
And the Cargo.toml
[package]
name = "foo"
version = "0.1.0"
authors = ["example <example@example.com>"]
edition = "2018"
[dependencies]
tokio = { version = "0.2", features = ["macros", "rt-threaded"] }
warp = "0.2"
mobc-postgres = { version = "0.5", features = ["with-chrono-0_4"] }
mobc = "0.5"
serde = {version = "1.0", features = ["derive"] }
serde_derive = "1.0"
serde_json = "1.0"
thiserror = "1.0"
chrono = { version = "0.4", features = ["serde"] }
log = "0.4.0"
env_logger = "0.7.1"
pretty_env_logger = "0.4.0"
[profile.dev]
debug = 0