Tear down

Recap

  1. 🦀Rust like to move it move it 🎵, borrow & when needed.

  2. 🦀Rust variable are immutable by default, mut when needed.

  3. 🦀Rust variable will drop when out of scope { }, consider borrow & when needed.

  4. No null, only Option, Use match (or other ways) to handle it; unwrap and expect will panic.

    #![allow(unused)]
    fn main() {
    enum Option<T> {
       Some(T),
       None,
    }
    }
  5. When fn return Result, Use match (or other ways) to handle it; unwrap and expect will panic.

    #![allow(unused)]
    fn main() {
    enum Result<T, E> {
       Ok(T),
       Err(E),
    }
    }
  6. Both Option, Result are enum so eat that frog 🐸!

  7. Generic T and E nearly like generic in TypeScript so it should be easy there.

  8. Use iter, into_iter, collect wisely, but no worry clippy will got your back anyway.

  9. Choose composition over inheritance, learn to love struct, impl, trait, derive instead.

  10. We impl (implement) some trait (aka skill) for struct so it can have that skill.

  11. String,Vec,Box are smart pointer allocated on heap.

  12. str, array, struct, and other primitives type are allocated on stack.

  13. Compiler will ask to add dyn when needed e.g. Box, Supertraits.

  14. Dynamic Dispatch (Box) can be replace with Static Dispatch if need.

  15. Don't over thinking! Do trust clippy and 🦀Rustacean and you will be fine.

  16. Did we forget Some(thing)? 🤔


Easy right? We're not done yet. Let's dig deeper! 👉 Continue to R4 ➠