【问题标题】:Cannot access parameters in Iron because the trait bound plugin::Plugin<iron::Request> is not satisfied无法访问 Iron 中的参数,因为 trait bound plugin::Plugin<iron::Request> 不满足
【发布时间】:2016-07-14 09:37:56
【问题描述】:

我正在探索 Iron Web 框架的功能。据我所知,Iron core 没有要处理的 API HTTP 参数,所以我尝试使用 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

我没有找到这个错误的踪迹,也不知道如何修复它。

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();
}

库的版本

iron = "0.4.0"
params = "0.2.2"

【问题讨论】:

标签: rust iron


【解决方案1】:

params 0.2.2 crate depends on iron ^0.3,所以需要将 Iron 依赖版本改为0.3

当使用这样的插件箱时,你必须确保版本完全匹配。有时可能还需要cargo update


在 Rust 中,从同一个 crate 的多个版本中提取的相同结构或特征被视为完全不同。它通常会导致类似“Pixel expected, but found Pixel”之类的错误,或者像您的情况一样缺少特征实现。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-04
    • 1970-01-01
    • 2021-12-04
    • 2016-01-04
    • 1970-01-01
    • 1970-01-01
    • 2017-05-17
    相关资源
    最近更新 更多