我正在尝试使用Iron框架的Hello World应用程序。这是我在main.rs中拥有的:

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)

最佳答案

Struct field shorthands went into Rust 1.17.0(和RFC 1682一样),因此您必须升级Rust安装。

如果您使用Rustup,请参见these instructions how to keep your Rust installation up-to-date

关于rust - 我如何摆脱错误 “struct field shorthands are unstable”?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45234980/

10-11 21:49
查看更多