Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the trait plugin::Plugin<iron::Request<'_, '_>> is not implemented for bodyparser::Raw #81

Open
Southclaws opened this issue Jul 17, 2018 · 1 comment

Comments

@Southclaws
Copy link

I tried to use the example as a reference to get my own code working, but it fails with:

error[E0277]: the trait bound `bodyparser::Raw: plugin::Plugin<iron::Request<'_, '_>>` is not satisfied
  --> src/main.rs:27:24
   |
27 |         let body = req.get::<bodyparser::Raw>();
   |                        ^^^ the trait `plugin::Plugin<iron::Request<'_, '_>>` is not implemented for `bodyparser::Raw`
   |
   = help: the following implementations were found:
             <bodyparser::Raw as plugin::Plugin<iron::request::Request<'a, 'b>>>

The code in question:

    let (tx, rx) = mpsc::channel();
    let sender = Mutex::new(tx);
    let chain = Chain::new(move |req: &mut Request| -> IronResult<Response> {
        println!("received request");

        let body = req.get::<bodyparser::Raw>();
        match body {
            Ok(Some(body)) => println!("Read body:\n{}", body),
            Ok(None) => println!("No body"),
            Err(err) => println!("Error: {:?}", err),
        }

        let tx = sender.lock().unwrap().clone(); //Or whatever
        tx.send("request");

        return Ok(Response::with((status::Ok, "Hello World")));
    });
    chain.link_before(Read::<bodyparser::MaxBodyLength>::one(MAX_BODY_LENGTH));

    thread::spawn(move || {
        for received in rx {
            println!("{}", received)
        }
    });

    match Iron::new(chain).http(env::var("BIND").unwrap()) {
        Ok(_) => println!("fine"),
        Err(error) => panic!("failed to bind HTTP listener: {:?}", error),
    }
@e-oz
Copy link

e-oz commented Jul 29, 2018

It's because bodyparser 0.8 is incompatible with iron 0.5. Use bodyparser 0.7 - only difference in code is the version of iron in configs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants