3
votes

I am trying to run the hyper example listed on the Github readme.

extern crate hyper;

use std::io::Write;

use hyper::Server;
use hyper::server::Request;
use hyper::server::Response;
use hyper::net::Fresh;

fn hello(_: Request, res: Response<Fresh>) {
    let mut res = res.start().unwrap();
    res.write_all(b"Hello World!").unwrap();
    res.end().unwrap();
}

fn main() {
    Server::http(hello).listen("127.0.0.1:3000").unwrap();
}

And the Cargo.toml looks like this:

[package]

name = <crate_name>
version = <version>
authors = <authors>

[dependencies]
hyper = "0.3"

However, when I attempt to build it using Cargo run I get the following error:

error: invalid character `-` in crate name: `build-script-build`
error: invalid character `-` in crate name: `pkg-config`
error: invalid character `-` in crate name: `rustc-serialize`

I looked through these different crates trying to see if maybe I could just change a "rustc-serialize" to "rustc_serialize" because I think that crate names can no longer have hyphens. However, I couldn't find anything of the sort. I would really like to be able to solve this problem because I have a feeling that I am going to run into this error a few more times while Rust is still being polished.

Edit: The versions are as follows: Rust: 1.0.0-beta.2 Hyper: 0.3.14 Cargo: 0.0.1-pre-nightly (built 2015-03-09)

1
Please include relevant version numbers, e.g., for rustc and Cargo. Without those, it's impossible to give any specific advice.BurntSushi5
Could you include the date in the cargo version number?huon

1 Answers

4
votes

Your version of Hyper seems to require a newer version of Rust, which automatically converts hyphens to underscores in crate names.

See RFC 940 and Issue #23533.