Rust language HelloWorld Web edition, rusthelloworld

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.