Fixes and content

This commit is contained in:
finga 2021-10-04 16:13:03 +02:00
parent 24f1ec76d8
commit 094d2546e9

View file

@ -69,7 +69,7 @@
- Careless (use of ~unsafe~ in) libraries can secretly break - Careless (use of ~unsafe~ in) libraries can secretly break
safety guarantees. safety guarantees.
** Problems and security Rust tries to conquer ** Problems Rust tries to conquer
#+BEGIN_CENTER #+BEGIN_CENTER
#+LaTeX:\includegraphics[width = 0.8\textwidth]{img/compiler_complaint.png} #+LaTeX:\includegraphics[width = 0.8\textwidth]{img/compiler_complaint.png}
[fn:xkcd_dangling_pointer] [fn:xkcd_dangling_pointer]
@ -93,14 +93,14 @@
--nomicon~) --nomicon~)
- Use '~$ rustup help docs~' to get an overview - Use '~$ rustup help docs~' to get an overview
*** Other helpful sites *** Compact "cheat sheets"
- [[https://cheats.rs][cheats.rs]] - [[https://cheats.rs][cheats.rs]]
- [[https://programming-idioms.org/cheatsheet/Rust][programming-idioms.org]] - [[https://programming-idioms.org/cheatsheet/Rust][programming-idioms.org]]
** Where to share, find help and stay up to date ** Where to share, find help and stay up to date
*** Online sharing/testing *** Online sharing/testing
- [[https://play.rust-lang.org/][play.rust-lang.org]] - [[https://play.rust-lang.org/][play.rust-lang.org]]
- [[https://godbolt.org/][godbolt.org]] (Not only for Rust, but it is also supported) - [[https://godbolt.org/][godbolt.org]] (Not only Rust is supported)
*** Chat (Discord) *** Chat (Discord)
- [[https://discord.gg/rust-lang][The Rust Programming Language]] - [[https://discord.gg/rust-lang][The Rust Programming Language]]
@ -115,9 +115,11 @@
- Semicolons have meaning (statements vs. expressions) - Semicolons have meaning (statements vs. expressions)
- Mutability - Mutability
- Shadowing - Shadowing
- Memory safety
- Ownership, references and lifetimes
- Functional paradigms - Functional paradigms
- Pattern matching - Pattern matching
- Memory safety - Metaprogramming (declarative and procedural macros)
- Meaningful compiler warnings and errors - Meaningful compiler warnings and errors
** Statements vs. expressions ** Statements vs. expressions
@ -127,7 +129,7 @@
fn_call(); fn_call();
#+END_SRC #+END_SRC
*** Expressions *** Expressions
~false~, ~x + y~, ~fn_call()~ ~false~, ~x + y~, ~fn_call()~, ~if~, ~match~
*** Example *** Example
#+BEGIN_SRC rust #+BEGIN_SRC rust
let bool_value = true; let bool_value = true;
@ -156,16 +158,18 @@
let baz = baz + 3; let baz = baz + 3;
#+END_SRC #+END_SRC
** Type aliases # ** Type aliases
*** Type aliases example # The ~type~ keywoard declares an alias of another type.
#+BEGIN_SRC rust
type Frequency = u64;
let clock: Frequency = 8_000_000
#[allow(non_camel_case_types)] # *** Type aliases example
type u64_t = u64; # #+BEGIN_SRC rust
let another_clock: Frequency = 16_000_000 as u64_t; # type Frequency = u64;
#+END_SRC # let clock: Frequency = 8_000_000
# #[allow(non_camel_case_types)]
# type u64_t = u64;
# let another_clock: Frequency = 16_000_000 as u64_t;
# #+END_SRC
** Tuple structs ** Tuple structs
*** Definition of a tuple struct *** Definition of a tuple struct
@ -208,14 +212,15 @@
let new_event = Event::Send("A message".to_owned()); let new_event = Event::Send("A message".to_owned());
#+END_SRC #+END_SRC
** ~if let~
** Pattern matching and some macros ** Pattern matching and some macros
@@latex:{\color{red}@@All match arms must return the same type!!1!@@latex:}@@
*** Simple ~match~ *** Simple ~match~
#+BEGIN_SRC rust #+BEGIN_SRC rust
match an_enum { match an_enum {
MyEnum::Something => todo!("This has to be done"), MyEnum::Something => todo!("This has to be done"),
MyEnum::SomethingElse(_) => unimplemented!("This is not implemented"), MyEnum::SmthngElse(_) => unimplemented!("This is unimplemented"),
MyEnum::AnotherThing(e) => println!("It is another thing: {}", e), MyEnum::AnotherThing(e) => println!("It is another thing: {}", e),
_ => unreachable!(), _ => unreachable!(),
}; };
@ -231,6 +236,16 @@
}; };
#+END_SRC #+END_SRC
** ~if let~
*** Simpler ~match~
#+BEGIN_SRC rust
if let Some(inner_value) = foo {
println!("Value: {}", inner_value);
} else {
println!("Nothing found");
}
#+END_SRC
** Loops[fn:reference_loops] ** Loops[fn:reference_loops]
*** Loops *** Loops
- ~loop~: infinite loops - ~loop~: infinite loops
@ -243,6 +258,44 @@
- ~continue~: exit the current iteration and jump to the loop - ~continue~: exit the current iteration and jump to the loop
header header
** Ownership
/Ownership/ is one of Rusts central concepts to achieve memory
safety without garbage collection.
*** Ownership Rules
- Each value has a variable that is called its /owner/.
- There can only be one owner at a time.
- When the owner goes out of scope, the value will be dropped.
** References
- A value can temporarily borrowed from its owner without
transferring ownership.
- There can be multiple immutable references.
- There can only be one mutable reference.
- The ~&~ symbol is the reference operator.
- The ~*~ symbol is the dereference operator.
- References are immutable by default, use the ~mut~ keyword to
make them mutable.
** Lifetimes
- The Rust compiler (borrow checker) keeps track of how long
references (borrows) are valid.
- To ensure valid borrows and therefor prevent dangling borrows
/Lifetimes/ are used.
- /Lifetimes/ are annotations which tell the borrow checker how
long a borrow needs to be valid.
- /Lifetimes/ are implicit and inferred, that means the compiler
infers /lifetimes/ wherever possible.
- /Lifetimes/ must be annotated when the borrow checker cannot
infer them on its own.
*** Struct with /lifetimes/
#+BEGIN_SRC rust
struct SomeApp<'a> {
config: &'a Config,
}
#+END_SRC
** Error related types ** Error related types
- Heavy use of ~Option<T>~ and ~Result<T, E>~ - Heavy use of ~Option<T>~ and ~Result<T, E>~
@ -327,7 +380,7 @@
#+END_SRC #+END_SRC
** Use more functional language features ** Use functional paradigms
- ~vec![1, 2, 3].iter()~ - ~vec![1, 2, 3].iter()~
- ~vec![1, 2, 3].iter().sum()~ - ~vec![1, 2, 3].iter().sum()~
- ~vec![1, 2, 3].iter().map(|x| x + 1).collect()~ - ~vec![1, 2, 3].iter().map(|x| x + 1).collect()~
@ -440,9 +493,11 @@
#+END_CENTER #+END_CENTER
** Install the Rust-Toolchain ** Install the Rust-Toolchain
*** Install Rust *** Install the Rust toolchain ([[https://rustup.rs][~rustup.rs~]])
From [[https://rustup.rs][rustup.rs]]: #+BEGIN_SRC sh
~$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh~ $ curl --proto '=https' --tlsv1.2 -sSf \
https://sh.rustup.rs | sh
#+END_SRC
*** Rustup: The Rust toolchain installer *** Rustup: The Rust toolchain installer
- Check for new versions: ~$ rustup check~ - Check for new versions: ~$ rustup check~
@ -454,31 +509,9 @@
- Activate nightly locally (in current dir): - Activate nightly locally (in current dir):
~$ rustup override set nightly~ ~$ rustup override set nightly~
** Handle the Rust toolchain with ~rustup~
*** Install the Rust toolchain ([[https://rustup.rs][~rustup.rs~]])
#+BEGIN_SRC sh
$ curl --proto '=https' --tlsv1.2 -sSf \
https://sh.rustup.rs | sh
#+END_SRC
*** Update ~rustup~
#+BEGIN_SRC sh
$ rustup self update
#+END_SRC
*** Check for updates for installed toolchains
#+BEGIN_SRC sh
$ rustup check
#+END_SRC
*** Update toolchains if outdated
#+BEGIN_SRC sh
$ rustup update
#+END_SRC
** IDE support aka are we IDE yet?[fn:areweideyet] ** IDE support aka are we IDE yet?[fn:areweideyet]
\tiny \tiny
#+attr_latex: :align c|ccccccccc
| | \rotatebox{90}{Syntax highlightning (.rs)} | \rotatebox{90}{Syntax highlightning (.toml)} | \rotatebox{90}{Snippets} | \rotatebox{90}{Code Completion} | \rotatebox{90}{Linting} | \rotatebox{90}{Code Formatting} | \rotatebox{90}{Go-to Definiton} | \rotatebox{90}{Debugging} | \rotatebox{90}{Documentation Tooltips} | | | \rotatebox{90}{Syntax highlightning (.rs)} | \rotatebox{90}{Syntax highlightning (.toml)} | \rotatebox{90}{Snippets} | \rotatebox{90}{Code Completion} | \rotatebox{90}{Linting} | \rotatebox{90}{Code Formatting} | \rotatebox{90}{Go-to Definiton} | \rotatebox{90}{Debugging} | \rotatebox{90}{Documentation Tooltips} |
|---------------------+--------------------------------------------+----------------------------------------------+--------------------------+---------------------------------+-------------------------+---------------------------------+---------------------------------+---------------------------+----------------------------------------| |---------------------+--------------------------------------------+----------------------------------------------+--------------------------+---------------------------------+-------------------------+---------------------------------+---------------------------------+---------------------------+----------------------------------------|
| Atom | X | X | X | X | X | X | X | | X | | Atom | X | X | X | X | X | X | X | | X |
@ -503,9 +536,11 @@
* Common Crates * Common Crates
** General ** General
*** General
- [[https://crates.io][crates.io]]/[[https://lib.rs][lib.rs]] - [[https://crates.io][crates.io]]/[[https://lib.rs][lib.rs]]
- [[https://github.com/rust-unofficial/awesome-rust][Awesome Rust]] - [[https://github.com/rust-unofficial/awesome-rust][Awesome Rust]]
*** Misc. Crates
- dotenv - dotenv
- [[https://tokio.rs/][tokio]] - [[https://tokio.rs/][tokio]]
@ -559,6 +594,11 @@
- refinery - refinery
- barrel - barrel
** Tui
- rustyline: Line editing library
- tui: Library for ncurses like things
- crossterm: Cross-platform terminal manipulation library
** Gui ([[https://www.areweguiyet.com/][areweguiyet.com]]) ** Gui ([[https://www.areweguiyet.com/][areweguiyet.com]])
A small selection of crates I used/tried so far: A small selection of crates I used/tried so far:
- [[https://sixtyfps.io/][SixtyFPS]] (WASM support) - [[https://sixtyfps.io/][SixtyFPS]] (WASM support)
@ -588,12 +628,11 @@
# - arm # - arm
** Unikernel ** Unikernel
https://unikernel.org For general information about unikernels visit [[https://unikernel.org][unikernel.org]].
- [[https://github.com/hermitcore/rusty-hermit][RustyHermit]] - [[https://github.com/hermitcore/rusty-hermit][RustyHermit]]
** Thats it for now ** Thats it for now
\Huge \Large
#+BEGIN_CENTER #+BEGIN_CENTER
Thank you for your attention! Thank you for your attention!
@ -603,11 +642,30 @@
\normalsize \normalsize
*** To be continued *** To be continued
- Lifetimes
- Borrowing and Arrowing **** Column left
:PROPERTIES:
:BEAMER_col: 0.45
:END:
- Traits - Traits
- Generics - Generics
- ~macro_rules!~ - Type Aliases vs. New Type Idioms
- Ownership
- References and Slices
- Lifetimes
- Iterators
- Functional paradigms
**** Column right
:PROPERTIES:
:BEAMER_col: 0.45
:END:
- Metaprogramming (macros)
- (Smart) Pointers
- Concurrency
- Object Oriented Programming
- Closures
- Async-Await
- ~unsafe~ Rust - ~unsafe~ Rust
* Footnotes * Footnotes