Tear down
Recap
-
🦀
Rustlike to move it move it 🎵, borrow&when needed. -
🦀
Rustvariable areimmutableby default,mutwhen needed. -
🦀
Rustvariable will drop when out of scope{ }, consider borrow&when needed. -
No
null, onlyOption, Usematch(or other ways) to handle it;unwrapandexpectwillpanic.#![allow(unused)] fn main() { enum Option<T> { Some(T), None, } } -
When
fnreturnResult, Usematch(or other ways) to handle it;unwrapandexpectwillpanic.#![allow(unused)] fn main() { enum Result<T, E> { Ok(T), Err(E), } } -
Both
Option,Resultareenumso eat that frog 🐸! -
Generic
TandEnearly like generic inTypeScriptso it should be easy there. -
Use
iter,into_iter,collectwisely, but no worryclippywill got your back anyway. -
Choose
compositionoverinheritance, learn to lovestruct,impl,trait,deriveinstead. -
We
impl(implement) sometrait(aka skill) forstructso it can have that skill. -
String,Vec,Boxare smart pointer allocated onheap. -
str,array,struct, and other primitives type are allocated onstack. -
Compiler will ask to add
dynwhen needed e.g.Box,Supertraits. -
Dynamic Dispatch(Box) can be replace withStatic Dispatchif need. -
Don't over thinking! Do trust
clippyand 🦀Rustaceanand you will be fine. -
Did we forget
Some(thing)? 🤔
Easy right? We're not done yet. Let's dig deeper! 👉 Continue to R4 ➠