Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

nickel is missing HttpRequest trait? #47

Closed
iamsebastian opened this issue Aug 5, 2016 · 2 comments
Closed

nickel is missing HttpRequest trait? #47

iamsebastian opened this issue Aug 5, 2016 · 2 comments

Comments

@iamsebastian
Copy link
Contributor

iamsebastian commented Aug 5, 2016

I've tried to implement this module in a fresh API, written in rust, but I can't get it to compile successfully. If I could get it to run, I would write an example integration for nickel in this project.

Maybe, there's a typo anywhere?

Cargo.toml

[package]
authors = ["Sebastian Blei <...>"]
name = "try_multipart"
version = "0.1.0"

[[bin]]
doc = false
name = "multipart"

[dependencies.multipart]
version = "0.7"
# Maybe a typo, because in the source code is a `nickel` cfg feature flag, NOT A `nickel_` (with underscore)
features = ["nickel", "nickel_"]

multipart.rs

#[macro_use]
extern crate nickel;
extern crate hyper;
extern crate multipart;

use multipart::server::{Entries, Multipart, SaveResult};
use multipart::server::nickel as nickel_;
use nickel::{Nickel, HttpRouter, MiddlewareResult, Request, Response};

// Try integration as full fn.
fn handle_post<'mw>(req: &mut Request, mut res: Response<'mw>) -> MiddlewareResult<'mw> {
    match Multipart::from_request(req) {
        Ok(mut multipart) => res.send("Ok"),
        Err(_) => res.send("error"),
    }
}

fn main() {
    let mut srv = Nickel::new();

    srv.post("/multipart/", middleware! { |req, res|
        match Multipart::from_request(req) {
            Ok(mut multipart) => "upload is multipart",
            Err(_) => "error",
        }
    });

    // Try integration via macro.
    // Macro and declared fn (handle_post) will be actually result in a similliar fn.
    srv.post("/alternative_multipart/", handle_post);

    srv.listen("127.0.0.1:6868");
}

cargo run --bin multipart will result in:

❯ cargo run --bin multipart
   Compiling try_multipart v0.1.0 (file:///home/sblei/Projects/macsi-rust-api)
src/bin/main.rs:62:11: 62:34 error: the trait bound `&mut nickel::Request<'_, '_>: multipart::server::HttpRequest` is not satisfied [E0277]
src/bin/main.rs:62     match Multipart::from_request(req) {
                             ^~~~~~~~~~~~~~~~~~~~~~~
src/bin/main.rs:62:11: 62:34 help: run `rustc --explain E0277` to see a detailed explanation
src/bin/main.rs:62:11: 62:34 note: required by `multipart::server::Multipart::from_request`
error: aborting due to previous error
error: Could not compile `diesel_pg_test`.

To learn more, run the command again with --verbose.

Thanks in advance for your help.

@abonander
Copy link
Owner

You don't write what version of Nickel you have in your Cargo.toml. If it doesn't match Multipart's, you'll get this error.

Also, the nickel_ feature implies nickel; the underscored feature is to make sure Hyper is activated as well since Nickel doesn't reexport Hyper's Request type. That's also what's blocking the upgrade to Hyper 0.9.

@iamsebastian
Copy link
Contributor Author

Argh.

I used hyper = 0.9 and nickel upstream from GitHub as source.

Fix

[dependencies.hyper]
default-features = false
version = "0.8"

[dependencies.multipart]
version = "0.7"
features = ["nickel_"]

[dependencies.nickel]
features = ["ssl", "unstable"]
version = "0.8"

Does the trick.

These moments, when you waste time to get something fixed which is not broken. 🐧

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

No branches or pull requests

2 participants