Basics of Rust
Mumblings
&
(slices) are just views to memory owned by some other var.
clone
when ran on &str
duplicates &str
. On doing on String
, you get a new copy.
Right way to do is var.to_owned()
or string::from
, latter is just more to type. (.to_string
can also do the job but hey, why learn a new thing to do the same stuff?)
Resources I Followed to Understand Concepts
Before you start, you must have some knowledge about:
- how to print output to console
- what traits are in rust
- ownership and borrow and mutability
- iterators
This is an excellent tutorial that would help you get up and running with the above concepts. The only thing that I’ll add would be:
- The tutorial suggests installing RLS in VSCode. That now has been replaced with other extension called rust-analyzer. He also suggest to enable autosave, that’s upto you to do it. If you’re coming from other languages, you may find that the editor might not show errors immediately after typing, and you’d need to hit Save. That’s why autosave is useful
- If you’re a JavaScript programmer, you can learn about iterators on https://javascript.info/iterable. Specifically cover “Symbol.iterator” and “String is iterable” parts.
I was in an interesting position as I’ve learnt Go before, wherein I learnt not only about channels but other ways to singal or share memory by using lower level primitives in sync
package. Along with I had some idea about string pool from Java as well, and from JS I knew about iterators maps and all. Given all this and the fact I’ve gone throw few Rust videos before (mostly after a time and then abandoning the progress I’ve made), when I revisited Rust this time, it clicked for me. I did not have to worry about many concepts about a system level programming language and learning Go made me realize Arc and all are just lower level primitives to share data safely across threads, other primitives are to conserve memory when not needed. After watching the videos I’ve listed below I actually sat and learn about Rust. I started going through https://github.com/sunface/rust-by-practice (few of its examples are not related to learning Rust, but overall it is good) and https://doc.rust-lang.org/rust-by-example/ (this has search button at the top!).
Below is the list of the list of the concepts:
- Fun video about borrow and ownership
- On boxes and heaps. As a JS programmer who has some but not much idea about lower lever concepts, I needed this.
- Stuff you can do with traits
- Downcasting
- Interior mutability, Arc, Rc, Cell, etc.
- Zero copy
- Macros
Debug/display
Time Travel Debugging With Rr
- https://gist.github.com/spacejam/15f27007c0b1bcc1d6b4c9169b18868c
- https://www.reddit.com/r/rust/comments/mwkkyn/a_light_wrapper_around_rr_the_timetravelling/
- https://www.travelneil.com/time-travel-debugging-in-rust.html
- https://github.com/sidkshatriya/me/blob/master/README.md
- JS used to had rr like facility in Firefox, the developer of which left Firefox and created replay.io
Rust Analyzer
I’ll shorten it to Analyzer
- Put
*
anywhere in LSP workspace symbol query to search for that symbol in installed crates and rustlib. Doesn’t work in VS Code as it strips off any star - After reading the error from cargo check, you can use Rust Analyzer’s code action to apply the hint.
Todo
- https://www.reddit.com/r/golang/comments/yerf3t/vhs_a_tool_for_generating_terminal_gifs_with_code/iu5tv29/
- What is
Vec<Box<dyn Draw>>
whereDraw
is a trait. Google: box dyn rust move
keyword- https://blog.cloudflare.com/pin-and-unpin-in-rust/
- https://github.com/dtolnay/rust-quiz
- https://github.com/lrlna/smol-zines
- Full thread https://twitter.com/terzi_federico/status/1481187234527150081?lang=en
- https://rust-book.cs.brown.edu/
- https://www.reddit.com/r/rust/comments/11gv52z/aquascope_interactive_visualization_of_rust/
- https://godbolt.org/
- https://doc.rust-lang.org/rust-by-example/
- https://prataprc.github.io/rust-crates-release-checklist.html
- once_cell https://old.reddit.com/r/rust/comments/126qaai/after_years_of_work_and_discussion_once_cell_has/jebg921/
- sealed traits https://old.reddit.com/r/rust/comments/12cj6as/a_definitive_guide_to_sealed_traits_in_rust/
- https://old.reddit.com/r/rust/comments/12c14ah/rust_vs_go_issue/
- https://www.reddit.com/r/rust/comments/112hmga/blog_post_when_rust_hurts/
- on why eyre-color over miette https://www.reddit.com/r/rust/comments/ylp4nz/what_crates_are_considered_as_defacto_standard/iv20gvt/
- spantrace https://www.reddit.com/r/rust/comments/gf6z3x/coloreyre_a_custom_context_for_eyre_which/fps6is9/
- https://www.reddit.com/r/rust/comments/yvdz6l/blog_post_designing_error_types_in_rust/
- https://github.com/miam-miam100/prse (sscanf in golang)