|
| 1 | ++++ |
| 2 | +title = "Introduction to Rust" |
| 3 | +date = 2022-10-10 |
| 4 | +weight = 1 |
| 5 | +[extra] |
| 6 | +lesson_date = 2022-10-10 |
| 7 | ++++ |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +# A language empowering everyone to build reliable and efficient software. |
| 12 | + |
| 13 | +([unofficial logo](https://rustacean.net/)) |
| 14 | + |
| 15 | +## Why use Rust? |
| 16 | + |
| 17 | +- It is **safe** (compared to C++ for example, as we will see in a minute) |
| 18 | +- It is **fast** (because it is compiled to machine code) |
| 19 | +- It is ergonomic and pleasant to use (static typing, expressive type system, helpful compiler |
| 20 | + warnings) |
| 21 | +- It |
| 22 | + is [loved by programmers](https://insights.stackoverflow.com/survey/2021#section-most-loved-dreaded-and-wanted-programming-scripting-and-markup-languages) |
| 23 | +- It provides excellent tooling |
| 24 | + |
| 25 | +## Why learn Rust? |
| 26 | + |
| 27 | +Even if you don't end up using Rust, learning it expands your horizons |
| 28 | + |
| 29 | +- it helps especially with the awareness of what you can and can't do in concurrent applications |
| 30 | +- it helps you understand memory management and learn its good practices |
| 31 | + |
| 32 | +## Why not to learn Rust? |
| 33 | + |
| 34 | +- Some people say Rust is too hard to learn because of the borrow checker |
| 35 | +- Once you get to know Cargo you won't ever want to use a language without a built-in package |
| 36 | + manager ;) |
| 37 | +- You will start hating C++ |
| 38 | + |
| 39 | +## Demos |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +Let's compare the same code written in [C](errors_demo.c), [C++](errors_demo.cpp) |
| 44 | +and [Rust](errors_demo.rs). |
| 45 | + |
| 46 | +## Code you sent me! |
| 47 | + |
| 48 | +### Aleksander Tudruj |
| 49 | + |
| 50 | +{{ include_code_sample(path="lessons/01_introduction/students/tudruj.cpp", language="cpp") }} |
| 51 | + |
| 52 | +### Krystyna Gasińska |
| 53 | + |
| 54 | +{{ include_code_sample(path="lessons/01_introduction/students/gasinska.py", language="python") }} |
| 55 | + |
| 56 | +### Antoni Koszowski |
| 57 | + |
| 58 | +{{ include_code_sample(path="lessons/01_introduction/students/koszowski.go", language="go") }} |
| 59 | + |
| 60 | +### Mieszko Grodzicki |
| 61 | + |
| 62 | +{{ include_code_sample(path="lessons/01_introduction/students/grodzicki.py", language="python") }} |
| 63 | + |
| 64 | +## Installing Rust |
| 65 | + |
| 66 | +- [Rustup](https://rustup.rs/) |
| 67 | +- Setup an IDE |
| 68 | + - [CLion](https://www.jetbrains.com/clion/) (you can get |
| 69 | + it [for free](https://www.jetbrains.com/community/education/)) |
| 70 | + and [Intellij-Rust](https://intellij-rust.github.io/) |
| 71 | + - [VSCode](https://code.visualstudio.com/) |
| 72 | + and [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer) |
| 73 | + - rust-analyzer also works |
| 74 | + with [other IDEs](https://rust-analyzer.github.io/manual.html#installation) |
| 75 | + |
| 76 | +## Useful tools |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | +- `cargo clippy` (for static analysis) |
| 81 | +- there's also `cargo check`, but it's less powerful than clippy |
| 82 | +- `cargo fmt` (for code formatting) |
| 83 | + |
| 84 | +### Rust Playground |
| 85 | + |
| 86 | +- [online Rust compiler](https://play.rust-lang.org/) |
| 87 | + |
| 88 | +## Hello world |
| 89 | + |
| 90 | +{{ include_code_sample(path="lessons/old/2021L/01_introduction/hello_world.rs", language="rust") }} |
| 91 | + |
| 92 | +### Variables |
| 93 | + |
| 94 | +{{ include_code_sample(path="lessons/old/2021L/01_introduction/variables.rs", language="rust") }} |
| 95 | + |
| 96 | +### Conditionals |
| 97 | + |
| 98 | +{{ include_code_sample(path="lessons/old/2021L/01_introduction/conditionals.rs", language="rust") }} |
| 99 | + |
| 100 | +### Loops |
| 101 | + |
| 102 | +{{ include_code_sample(path="lessons/old/2021L/01_introduction/loops.rs", language="rust") }} |
| 103 | + |
| 104 | +### Functions |
| 105 | + |
| 106 | +{{ include_code_sample(path="lessons/old/2021L/01_introduction/functions.rs", language="rust") }} |
| 107 | + |
| 108 | +## Test assignment (not graded) |
| 109 | + |
| 110 | +Click [here](https://classroom.github.com/a/P_z-gHH-) |
| 111 | + |
| 112 | +## Obligatory reading |
| 113 | + |
| 114 | +- [The Book, chapters 1-3](https://doc.rust-lang.org/stable/book/) |
| 115 | + |
| 116 | +## Additional reading |
| 117 | + |
| 118 | +- [Rust By Example](https://doc.rust-lang.org/stable/rust-by-example/) |
0 commit comments