Rust Language
This section is designed to provide a quick reference for Rust's language features, syntax, and best practices.
It is not intended to be a beginner's book nor a comprehensive guide, but rather a tool for those who are looking to refresh their knowledge. The Rust book
↗ is an excellent resource for complete beginners to get started with. Refer as well to the books chapter for a list of relevant books.
Rust Installation and First Steps
Entry Points
Define the Entrypoint of your Application with the Main Function |
Define the Entrypoint of your Asynchronous Application |
Data Types
Use Scalar Data Types |
Declare and Use Compound Data Types: Tuples and Arrays |
Use the Unit and Never Special Types |
Declare Strings |
Declare a Type Alias |
Variables
Constants and Statics
Ownership and Borrowing
Ownership |
Move Semantics |
Clone (Deep Copy) |
Copy Semantics |
References and Borrowing |
Borrowing when Calling a Function |
Lifetimes
Slices
Control Flow
Execute Code based on a Condition Using if and else |
Create Loops Using loop |
Execute Code Repeatedly While a Condition is True with while |
Iterate Through a Collection with for |
Exit Early from Blocks |
Pattern Matching
Functions
Write a Rust Function |
Write a Generic Function |
Return a Reference from a Function |
Work with Diverging Functions |
Work with Function Pointers |
Closures
Closure Syntax |
Force Closure Capture by Value |
Annotate Closure Types |
Use Closures as Function Arguments |
Structs
Enums
Traits
Impl Trait
Simplify Method Signatures with impl Trait |
Return Opaque Types (esp. Closures and Iterators) with Return-position impl Trait |