我正在尝试使用Iron框架的Hello World应用程序。这就是我的主要内容:
extern crate iron;
extern crate router;
use iron::prelude::*;
use iron::status;
use router::Router;
fn main() {
let mut router = Router::new();
router.get("/", hello_world);
router.post("/data", randomfriend);
fn hello_world(_: &mut Request) -> IronResult<Response> {
Ok(Response::with((status::Ok, "Hello World!")))
}
fn data(_: &mut Request) -> IronResult<Response> {
Ok(Response::with((status::Ok, "Got some data")))
}
Iron::new(router).http("localhost:3000").unwrap();
println!("On 3000");
}
这是我的Cargo.toml:
[package]
name = "webserver-iron"
version = "0.1.0"
[[bin]]
name = "webapp_demo_server"
[dependencies]
iron = "*"
router = "*"
当我运行cargo run
时,我收到以下错误:
error: struct field shorthands are unstable (see issue #37340)
似乎已经修复了这个问题,但我怎么能摆脱它呢?我有以下Rust版本:
rustc 1.16.0 (30cf806ef 2017-03-10)
答案 0 :(得分:7)
Struct field shorthands went into Rust 1.17.0(作为RFC 1682),因此您必须升级Rust安装。
如果您使用Rustup,请参阅these instructions how to keep your Rust installation up-to-date。