Search code examples
rustnickel

Rust Nickel Hello World tutorial throwing dependency error when run


I am learning Rust, and saw a post on http://reddit.com/r/rust yesterday for Nickel. As a Node.js developer in my free time, I was interested in checking this out.

I downloaded the Rust 1.0.0-beta DMG from http://rust-lang.org.

I followed the Hello World tutorial precisely, and when I execute cargo run in my Terminal, I am receiving the following error:

Robs-MacBook-Pro:nickel-demo rob$ cargo run
   Compiling nickel-demo v0.0.1 (file:///Users/rob/Workbench/nickel-demo)
src/main.rs:4:1: 4:21 error: an external crate named `nickel` has already been imported into this module [E0259]
src/main.rs:4 extern crate nickel;
              ^~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
Could not compile `nickel-demo`.

The Hello World main.rs file for the Nickel Demo looks like this:

extern crate nickel;

#[macro_use] extern crate nickel_macros;
extern crate nickel;

use nickel::Nickel;

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

    server.utilize(router! {
        get "**" => |_req, _res| {
            "Hello world!"
        }
    });

    server.listen("127.0.0.1:6767");
}

As I was typing this code into my editor, I specifically thought it was weird that I was declaring extern crate nickel; twice in the file. After receiving the error I refactored the code to this:

extern crate nickel;

#[macro_use] extern crate nickel_macros;

use nickel::Nickel;

...

And I get this error:

Robs-MacBook-Pro:nickel-demo rob$ cargo run
   Compiling nickel-demo v0.0.1 (file:///Users/rob/Workbench/nickel-demo)
     Running `target/debug/nickel-demo`
Listening on http://127.0.0.1:6767
Ctrl-C to shutdown server
thread '<main>' panicked at 'arithmetic operation overflowed', /Users/rob/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.3.11/src/server/mod.rs:90
An unknown error occurred

Solution

  • The arithmetic operation overflowed bug seems to be an upstream issue. It also affects hyper which nickel depends on.

    See https://github.com/seanmonstar/num_cpus/issues/2

    As a temporary workaround use cargo build --release to prevent the checks altogether.