]> git.proxmox.com Git - rustc.git/blob - src/doc/rust-by-example/src/hello.md
New upstream version 1.37.0+dfsg1
[rustc.git] / src / doc / rust-by-example / src / hello.md
1 # Hello World
2
3 This is the source code of the traditional Hello World program.
4
5 ```rust,editable
6 // This is a comment, and is ignored by the compiler
7 // You can test this code by clicking the "Run" button over there ->
8 // or if you prefer to use your keyboard, you can use the "Ctrl + Enter" shortcut
9
10 // This code is editable, feel free to hack it!
11 // You can always return to the original code by clicking the "Reset" button ->
12
13 // This is the main function
14 fn main() {
15 // Statements here are executed when the compiled binary is called
16
17 // Print text to the console
18 println!("Hello World!");
19 }
20 ```
21
22 `println!` is a [*macro*][macros] that prints text to the
23 console.
24
25 A binary can be generated using the Rust compiler: `rustc`.
26
27 ```bash
28 $ rustc hello.rs
29 ```
30
31 `rustc` will produce a `hello` binary that can be executed.
32
33 ```bash
34 $ ./hello
35 Hello World!
36 ```
37
38 ### Activity
39
40 Click 'Run' above to see the expected output. Next, add a new
41 line with a second `println!` macro so that the output
42 shows:
43
44 ```text
45 Hello World!
46 I'm a Rustacean!
47 ```
48
49 [macros]: macros.md