summaryrefslogtreecommitdiff
path: root/3 Resources/Programming/Rust.md
blob: 8724ca392718ffeafd3c60707e551076967f9a61 (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
https://rust-book.cs.brown.edu

> Finished chapter 2. Onto chapter 3!

If the name ends with ! it's a macro.

By default, Rust has a set of items defined in the standard library that it brings into the scope of every program. This set is called the _prelude_, and you can see everything in it [in the standard library documentation](https://doc.rust-lang.org/std/prelude/index.html).

"he `stdin` function returns an instance of [`std::io::Stdin`](https://doc.rust-lang.org/std/io/struct.Stdin.html), which is a type that represents a handle to the standard input for your terminal."
How does this work? How does it know which terminal is ours? I guess it might be connected by linux when running the process as `/proc/<pid>/stdin`.

`&` is a reference. References are also immutable by default, thus `&mut guess` will allow us to update the reference to the variable guess.

Enum members are called variants.

`cargo doc --open` command will build documentation provided by all your dependencies locally and open it in your browser.

`match`  expression -> arms -> pattern +  code path. Match expressions stop evaluating if a match is made; therefore we should strive to order them based on their likeliness to be hit.

`shadowed` = when a variable name is used multiple times; e.g
```
let x = 1
let x = 2 <- shadowed
```
Shadowing is different from making a variable `mutable` because it is fully reassigned (thus its type can also be changed), but the value is then still immutable (giving compiler errors when we try to reassign).

![[Integer types Rust.png]]