Skip to content
cuppar edited this page Jul 28, 2023 · 23 revisions

Learn Rust by 500 lines code

crate_version crate_downloads license

English | 中文


Next >


(This tutorial is under development, unfinished parts will be marked with [TODO])

Extended reading: Tutorial progress notes

Result preview

You can preview what you can get through this tutorial.

Why learn Rust

  • Performance/security/productivity, many programming languages can only choose two of these three trade-offs, but Rust has all three
  • The linux kernel has always only recognized the C language, and Rust has created history, becoming the first official non-C language in history entering the linux kernel
  • Microsoft is rewriting parts of the Windows kernel in Rust
  • World-class development experience and tool chain, Rust is the language with the best development experience I have ever used, none of them
    • rustup Rust itself and the corresponding tool chain installation/upgrade/multi-version functions, one-click management
    • cargo Rust project dependencies/build/unit test/integration test/release/update, one-click management
    • rustfmt Rust's official formatting tool, no more holy wars over brackets and newlines
    • rustdoc Rust's automatic documentation generation tool, the code is written, the document is written
  • The most important point is: Safe Rust compiles == no bugs (no dealing pointers/dealing references/memory leaks, except logic bugs)

Why learn Rust through RTD

  • Concise, with 500 lines of code tutorial to teach you 80% of the most commonly used knowledge in Rust
  • Learning by doing has a higher knowledge retention rate than just watching but not doing, only reading but not writing
  • Rust has world-class documentation and tutorials, but if you're a Rust beginner, you've probably heard of Rust's steep learning curve, like myself, where I spent 5+ hours a day for 2 months before I was able to write this tutorial, and I only learned less than half of the knowledge I have read. In the process of making this tutorial, my understanding of some knowledge points is gradually deepening. By following RTD to complete a small project, you will be familiar with the most commonly used functions in Rust, it will be more comfortable to read Rust's excellent and thick "Bible". Excellent Rust material includes, but is not limited to:
  • If you have read some of the above material, then you will be able to follow the RTD tutorial more easily, but that is not necessary, I will assume that you know nothing about Rust

Pre-knowledge

  • Familiar with simple programming experience in any programming language, know what is variable, condition, loop, scope, etc.
  • Understand some simple computer basics, such as knowing what is the difference between main memory (memory) and auxiliary memory (hard disk), simple data structures, such as arrays and so on, etc.

Who is suitable for learning

In short, anyone familiar with any programming language, especially engineers in some of the following fields:

  • Front-end development, the future of the front-end is the Web, the future of the Web is WebAssembly, Rust is currently the most suitable language for WebAssembly development.
  • Backend development, Rust fearless concurrency, performance comparable to C and formally verified memory safety/thread safety Which backend do not love?
  • System development, Rust will eventually surpass C language.
  • Embedded development, another home of Rust.
  • Blockchain development, the vast majority of blockchains you can find on the market use Rust
  • Any other scene developers that require high security/high performance

Who is not suitable for learning

  • Programming beginners, Rust is not suitable for learn programming as the first language entry
    • I thought so at first
    • But after contacting the feedback from some people in the Rust community who are actually using Rust as their first programming language, I think I should reconsider whether this view is correct
  • Special note: Engineers who are too proficient in a specific language need to put aside stereotyped concepts in their minds when they first learn Rust. Because Rust is quite different from most mainstream programming languages due to its breakthrough and innovative features, if you are too proficient in a specific language, you will inevitably bring in some existing concepts, which will easily cause confusion

Tutorial notes

  • Assume that the reader knows nothing about Rust. I will stop and explain every new Rust-related concept in the tutorial when it first appears, and I will not assume that you have the corresponding background knowledge
  • Each chapter has the complete code of the chapter, which can be run directly
  • Game-based learning, divided into two lines, the main line and the branch line
    • Main line: Complete RTD CLI App
      • Just want to be able to use it, and don't do in-depth exploration of some advanced concepts to ensure that you can easily make applications
    • Branch line: extended reading of some Rust knowledge points or computer science concepts encountered in the process
      • usually explain the principle
      • why is it designed like this
      • what tradeoffs were made
      • What are the pros and cons, etc.

Branch extended reading will like this:

Extended reading: XXX

link to the page in [en]ext_XXX format page (most likely [TODO] at the beginning of tutorial writing)


Interesting fact: I use RTD to complete the RTD tutorial :)


Next >