我有一个超级简单的网络服务器,由于某种原因,该println!
语句被打印了两次。为什么会这样?
extern crate iron;
use iron::prelude::*;
use iron::status;
fn hello_world(_: &mut Request) -> IronResult<Response> {
println!("Said Hello World");
Ok(Response::with((status::Ok, "Hello World\n")))
}
fn main() {
Iron::new(hello_world).http("localhost:8000").unwrap();
}
每次我刷新浏览器时,shell 中的输出都是:
Said Hello World
Said Hello World
我只希望该行被打印一次。似乎我的hello_world
函数被调用了两次。我错过了什么?