Performant Software Systems with Rust — Lecture 2
Rust is one of the most exciting languages in the recent years
Yet, it is known to be a complex language with a steep learning curve
But I’ve got some good news for you.
It can be simple if you learn it the hands-on way.
JSONDecodingError On Line 1
NullPointerException
IndexError In File <in>
error: expected one of `:`, `@`, or `|`, found `)`
--> main.rs:1:14
1 | fn hello(name) {
| ^ expected one of `:`, `@`, or `|`
|
help: if this is a `self` type, give it a parameter name
|
1 | fn hello(self: name) {
| +++++
help: if this is a parameter name, give it a type
|
1 | fn hello(name: TypeName) {
| ++++++++++
help: if this is a type, explicitly ignore the parameter
|
1 | fn hello(_: name) {
| ++
error[E0369]: cannot add `String` to `&str`
--> main.rs:2:21
|
2 | return "hello " + name
| -------- ^ ---- String
| | |
| | `+` cannot be used to concatenate
| a `&str` with a `String`
| &str
|
help: create an owned `String` on the left
and add a borrow on the right
|
2 | return "hello ".to_owned() + &name
| +++++++++++ +
error[E0369]: cannot add `String` to `&str`
--> main.rs:2:21
|
2 | return "hello " + name
| -------- ^ ---- String
| | |
| | `+` cannot be used to concatenate
| a `&str` with a `String`
| &str
|
help: create an owned `String` on the left
and add a borrow on the right
|
2 | return "hello ".to_owned() + &name
| +++++++++++ +
error[E0369]: cannot add `String` to `&str`
--> main.rs:2:21
|
2 | return "hello " + name
| -------- ^ ---- String
| | |
| | `+` cannot be used to concatenate
| a `&str` with a `String`
| &str
|
help: create an owned `String` on the left
and add a borrow on the right
|
2 | return "hello ".to_owned() + &name
| +++++++++++ +
error[E0369]: cannot add `String` to `&str`
--> main.rs:2:21
|
2 | return "hello " + name
| -------- ^ ---- String
| | |
| | `+` cannot be used to concatenate
| a `&str` with a `String`
| &str
|
help: create an owned `String` on the left
and add a borrow on the right
|
2 | return "hello ".to_owned() + &name
| +++++++++++ +
error[E0369]: cannot add `String` to `&str`
--> main.rs:2:21
|
2 | return "hello " + name
| -------- ^ ---- String
| | |
| | `+` cannot be used to concatenate
| a `&str` with a `String`
| &str
|
help: create an owned `String` on the left
and add a borrow on the right
|
2 | return "hello ".to_owned() + &name
| +++++++++++ +
error[E0369]: cannot add `String` to `&str`
--> main.rs:2:21
|
2 | return "hello " + name
| -------- ^ ---- String
| | |
| | `+` cannot be used to concatenate
| a `&str` with a `String`
| &str
|
help: create an owned `String` on the left
and add a borrow on the right
|
2 | return "hello ".to_owned() + &name
| +++++++++++ +
Let’s try running rustc --explain E0308
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Beautiful one-liner install
rustup update
rustup doc
Or directly open the Rust Book
rustup doc --book
rustc main.rs
Three items have been created for you
Cargo.toml
src/main.rs
Cargo.toml
cargo doc # local package documentation
cargo bench # built-in benchmarking
cargo test # built-in parallel testing
cargo add aws-sdk # easily add dependencies
cargo install # install exes into .cargo/bin
cargo clippy # run the code linter
cargo publish # publish packages to crates.io
Everything related to Rust on fasterthanli.me
Rust By Example https://doc.rust-lang.org/rust-by-example/
Your code can be perfect
The Guessing Game
Cargo.toml
cargo doc --open
The Rust Programming Language, Chapter 1-2