HelloWorld Web version of rust language _rust

Source: Internet
Author: User
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.



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.