Rust language HelloWorld Web edition, rusthelloworld
HelloWorld Web version of Rust Language
The following article is worth studying:
Http://arthurtw.github.io/2014/12/21/rust-anti-sloppy-programming-language.html
Iron is a Web framework built on hyper. hyper is an http library fully written by Rust. Therefore, Iron is equivalent to Tomcat/Jetty in Java,
Cowboy is for Erlang. The following describes how to use Iron to write a WebServer. When a user accesses http: // localhost: 3000 in the address bar of a browser,
The browser returns HelloWorld.
It's easy, just three steps:
1) install Rust. Refer to my series of articles: http://blog.csdn.net/ubuntu64fan/article/details/47863935
2) create a HelloWorld project. Refer to my series of articles: http://blog.csdn.net/ubuntu64fan/article/details/48370617
3) Modify hello_world/Cargo. toml and add the following content:
[dependencies]iron = "*"
Modify hello_world/src/main. rs with the following content:
extern crate iron;use iron::prelude::*;use iron::status;fn main() { fn hello_world(_: &mut Request) -> IronResult<Response> { Ok(Response::with((status::Ok, "Hello World!"))) } Iron::new(hello_world).http("localhost:3000").unwrap(); println!("On 3000");}
Then run the compilation command below hello_world:
# cargo build# cargo run
Running 'target/debug/hello_world'
Open the browser and check: localhost: 3000
Hello World!
Several terminologies of Rust:
Cargo: The construction tool of the rust language. It is very image-oriented. It refers to trucks.
Crate: equivalent to java jar package, so of c/c ++. Wicker boxes. Various wicker boxes are installed in the van.
Rustc: The rust compiler.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.