Rust Language HelloWorld Web Edition

Source: Internet
Author: User

Rust Language HelloWorld Web Edition

The following article is worth reading carefully:

Http://arthurtw.github.io/2014/12/21/rust-anti-sloppy-programming-language.html


Iron is a web framework that is built on top of hyper, and hyper is an HTTP library written entirely in rust. Therefore, iron is equivalent to Tomcat/jetty to Java,

Cowboy to Erlang. The following is the use of iron write a webserver, very simple, when the user in the browser address bar access to http://localhost:3000,

Browser return: HelloWorld.

Very simple, just 3 steps:

1) Install rust. Refer to my article series: http://blog.csdn.net/ubuntu64fan/article/details/47863935

2) Create a HelloWorld project. Refer to my article series: http://blog.csdn.net/ubuntu64fan/article/details/48370617

3) Modify the HELLO_WORLD/CARGO.TOML to add the following content:

[Dependencies]iron = "*"

To modify 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), Ironres ult<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 a browser, view: localhost:3000

Hello world!

Rust several terms:

Cargo:rust language Construction tools, very image, truck, put things in the meaning of loading.

Crate: A Java-equivalent jar package, A/C + + so. Wicker box, a variety of wicker boxes loaded in the lorry.

Compiler for Rustc:rust languages.



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Rust Language HelloWorld Web Edition

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.