The HelloWorld web version of Rust language
The following article is worth studying carefully:
Http://arthurtw.github.io/2014/12/21/rust-anti-sloppy-programming-language.html
Iron is a web framework, built on hyper, and hyper is a completely HTTP library written with Rust. Therefore, iron is equivalent to Tomcat/jetty in Java,
Cowboy to Erlang. Use iron to write a webserver, very simple, when users access http://localhost:3000 in the browser address bar,
Browser return: HelloWorld.
Very simple, just 3 steps:
1) Install rust. Reference to my series of articles: http://blog.csdn.net/ubuntu64fan/article/details/47863935
2) Create a HelloWorld project. Reference to my series of articles: http://blog.csdn.net/ubuntu64fan/article/details/48370617
3) Modify HELLO_WORLD/CARGO.TOML, add the following content:
[Dependencies]
Iron = "*"
To modify the hello_world/src/main.rs, the full contents are as follows:
extern crate Iron;
Use iron::p relude::*;
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 compile command under hello_world/:
# Cargo Build
# cargo Run
Running ' Target/debug/hello_world '
Open Browser, view: localhost:3000
Hello world!
Rust Several terms:
Cargo:rust language Construction tools, very image, truck, put things into the meaning.
Crate: Java-equivalent jar pack, and C + + so. A wicker box with various wicker boxes in the van.
Compiler for Rustc:rust language.