Variable Declaration
Browse / Rust Programming Language Cheatsheet
Rust Programming Language Cheatsheet
A concise reference for the Rust programming language, covering syntax, data structures, control flow, and advanced features.
Basics & Syntax
Fundamental Syntax
|
|
|
|
Functions |
|
|
Comments |
// Single-line comment /* |
|
Printing to Console |
|
|
Semicolons |
Statements end with a semicolon |
|
Modules |
|
Data Types
|
Scalar Types:
|
|
Compound Types:
|
|
String Types:
|
Ownership and Borrowing
|
Rust’s ownership system prevents memory errors. Ownership Rules:
|
|
Borrowing:
|
|
Lifetimes: |
Control Flow & Data Structures
Control Flow
|
If/Else |
|
|
Loops |
|
|
Match |
|
Data Structures
|
Structs:
|
|
Enums:
|
|
Vectors:
|
|
Hash Maps:
|
Error Handling
|
|
|
|
|
|
Advanced Features
Traits
|
Similar to interfaces in other languages. Define shared behavior.
|
|
Trait Bounds: Specify that a generic type must implement a certain trait.
|
Generics
|
Generic Functions |
|
|
Generic Structs |
|
Closures
|
Anonymous functions that can capture their environment.
|
|
Capturing variables:
|
Concurrency
|
Threads:
|
|
Channels:
|
|
Mutexes:
|
Cargo & Crates
Cargo Commands
|
Cargo.toml
|
The manifest file for Rust projects. Specifies dependencies, metadata, etc.
|
Crates
|
Packages of Rust code.
|
|
Common Crates:
|