I am exploring the capabilities of the Iron web framework. As far as I have figured out, the Iron core doesn't have an API to handle HTTP parameters so I tried to use the params crate.
error: the trait bound `params::Params: plugin::Plugin<iron::Request<'_, '_>>` is not satisfied [E0277]
let map = req.get_ref::<Params>().unwrap();
^~~~~~~
help: run `rustc --explain E0277` to see a detailed explanation
I haven't found trace of this bug and don't have a clue how to fix it.
extern crate iron;
extern crate params;
use iron::prelude::*;
use iron::status;
use params::*; //{self, Params, Value};
fn handle_user(req: &mut Request) -> IronResult<Response> {
use params::{Params, Value};
let map = req.get_ref::<Params>().unwrap();
match map.find(&["user", "name"]) {
Some(&Value::String(ref name)) if name == "Marie" => {
Ok(Response::with((iron::status::Ok, "Welcome back, Marie!")))
},
_ => Ok(Response::with(iron::status::NotFound)),
}
}
fn main() {
Iron::new(handle_user).http("localhost:2330").unwrap();
}
Versions of libraries
iron = "0.4.0"
params = "0.2.2"
The params 0.2.2
crate depends on iron ^0.3
, so you need to change the iron dependency version to 0.3
.
When using such a plugin crate, you have to make sure that versions match exactly. Sometimes a cargo update
may be needed also.
In Rust, the same structs or traits taken from multiple versions of the same crate are treated as totally different. It usually results in an error like "Pixel
expected, but found Pixel
", or missing trait implementations as in your case.