Cannot access parameters in Iron because the trait bound plugin::Plugin<iron::Request> is not satisfied

戏子无情 提交于 2019-12-24 00:57:36

问题


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"

回答1:


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.



来源:https://stackoverflow.com/questions/38370713/cannot-access-parameters-in-iron-because-the-trait-bound-pluginpluginironre

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!