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