I'm trying to build a web service with Iron using this source as a tutorial, but I'm getting errors during compilation of hyper:
Compiling hyper v0.9.17
/root/.cargo/registry/src/github.com-88ac128001ac3a9a/hyper-0.9.17/src/header/common/accept_language.rs:62:23: 62:30 error: macro undefined: 'langtag!'
/root/.cargo/registry/src/github.com-88ac128001ac3a9a/hyper-0.9.17/src/header/common/accept_language.rs:62 qitem(langtag!(en;;;US)),
^~~~~~~
/root/.cargo/registry/src/github.com-88ac128001ac3a9a/hyper-0.9.17/src/header/common/accept_language.rs:63:34: 63:41 error: macro undefined: 'langtag!'
/root/.cargo/registry/src/github.com-88ac128001ac3a9a/hyper-0.9.17/src/header/common/accept_language.rs:63 QualityItem::new(langtag!(en), Quality(500)),
^~~~~~~
/root/.cargo/registry/src/github.com-88ac128001ac3a9a/hyper-0.9.17/src/header/common/accept_language.rs:64:23: 64:30 error: macro undefined: 'langtag!'
/root/.cargo/registry/src/github.com-88ac128001ac3a9a/hyper-0.9.17/src/header/common/accept_language.rs:64 qitem(langtag!(fr)),
^~~~~~~
Versions I'm using:
Cargo.toml
[package]
name = "hello"
version = "0.1.0"
authors = ["root"]
[dependencies]
language-tags = "0.2.2"
iron = "0.4.0"
main.rs:
extern crate iron;
use iron::prelude::*;
use iron::status;
use iron::mime::Mime;
fn main() {
Iron::new(|_: &mut Request| {
let content_type = "application/json".parse::<Mime>().unwrap();
Ok(Response::with((content_type, status::Ok, "{ respone: \"Hello world!\" }")))
}).http("localhost:3009").unwrap();
}
I only added the language-tags in the Cargo.toml because I thought it would be solve my problem. Additional changes were not made.
An old version of Rust was causing the problem. Today's stable version of Rust is 1.14.0, but on my Digital Ocean VM, Rust 1.7 was preinstalled. Even after running the official installer, the version was still 1.7:
curl https://sh.rustup.rs -sSf | sh
After the installation it says:
Welcome to Rust!
This will download and install the official compiler for the Rust programming language, and its package manager, Cargo.
It will add the cargo, rustc, rustup and other commands to Cargo's bin directory, located at:
/root/.cargo/bin
This path will then be added to your PATH environment variable by modifying the profile file located at:
/root/.profile
I use zsh which doesn't use ~/.profile. So the PATH
environment variable wasn't changed for me and therefor the command cargo run
pointed to the preinstalled old version in /usr/bin/cargo
and not to ~/.cargo/bin
.
You can find out where the executables are located with the command which cargo
or which rustc
.
The solution was to use ~/.cargo/bin/cargo run
. For zsh, you can also add the folder ~/.cargo/bin
to your PATH
environment variable by adding
export PATH="~/.cargo/bin:$PATH"
to your .zshrc