Index of Examples
Algorithms
Randomness
Sorting
Recipe | Crates | Categories |
---|---|---|
Sort a Vector of Integers | ||
Sort a Vector of Floats | ||
Sort a Vector of Structs |
Data Structures
Binaryheap
Recipe | Crates | Categories |
---|---|---|
priority-queue |
Bitfield
Recipe | Crates | Categories |
---|---|---|
Define and Operate on a Type Represented as a Bitfield | ||
flagset | ||
bitvec |
Btrees
Recipe | Crates | Categories |
---|---|---|
BTreeMap<K, V> | ||
BTreeSet<T> |
Graph
Recipe | Crates | Categories |
---|---|---|
Manipulate Graphs with petgraph |
Hashmap
Recipe | Crates |
---|---|
Store Key-Value Pairs into a HashMap | |
Store Unique Items in a HashSet | |
Use a Custom Type as the Key of a HashMap | |
Use a Custom Hash Function with HashMap and HashSet |
Heapless
Recipe | Crates | Categories |
---|---|---|
Heapless |
LinkedList
Recipe | Crates | Categories |
---|---|---|
Stored Data in a Linked List |
Maps
Recipe | Crates | Categories |
---|---|---|
Store Data in an Insertion-ordered Map | ||
Store Data in a multimap | ||
Store Collections of Objects that Need Stable, Safe References |
Stack Allocated Arrays
Stack and Queue
Recipe | Crates | Categories |
---|---|---|
Implement a Queue Using VecDeque | ||
Implement a Stack Using Vec |
Strings
Recipe | Crates |
---|---|
String and &str | |
Print and Format Strings | |
Concatenate Strings |
UUID
Recipe | Crates | Categories |
---|---|---|
Generate and Parse UUIDs |
Vector
Filesystem
Directories
Recipe | Crates | Categories |
---|---|---|
Get the Current Working Directory | ||
remove_dir_all |
Directory Traversal
File Watching
Recipe | Crates | Categories |
---|---|---|
Watch Files or Directories and Execute a Function When They Change |
Read-Write
Recipe | Crates | Categories |
---|---|---|
Read Lines of Strings from a File | ||
Avoid Writing and Reading from the Same File | ||
Access a File Randomly Using a Memory Map |
tempfile
Recipe | Crates | Categories |
---|---|---|
Create Temporary Files or Temporary Directories |
User Directories
Recipe | Crates | Categories |
---|---|---|
dirs | ||
directories | ||
Open a File or URL using the Program Configured on your System |
Mathematics
Additional Numeric Types
Recipe | Crates | Categories |
---|---|---|
Abstract over Different Number Types | ||
Use Big Integers | ||
Use Big Decimals | ||
Sort Floats | ||
num-bigint | ||
num | ||
rug | ||
typenum |
Complex Numbers
Recipe | Crates | Categories |
---|---|---|
Create Complex Numbers | ||
Add Complex Numbers | ||
Use Mathematical Functions on Complex Numbers |
Linear Algebra
Recipe | Crates | Categories |
---|---|---|
Calculate Vector Norms | ||
Add Matrices | ||
Multiply Matrices | ||
Multiply a Scalar with a Vector and a Matrix | ||
Invert a Matrix | ||
Compare Vectors | ||
(De)serialize a Matrix |
Statistics
Recipe | Crates | Categories |
---|---|---|
Calculate Measures of Central Tendency | ||
Compute the Standard Deviation |
Trigonometry
Recipe | Crates | Categories |
---|---|---|
Calculate the Side Length of a Triangle | ||
Verify that tan is Equal to sin Divided by cos | ||
Calculate the Distance Between two Points on Earth |
Code: Organization
Code Organization By Project Type
Dependencies
Modules
Structure your Code into Modules |
Split your Code into Several Files |
Access Items Within Modules via Paths |
Use Modules to Hide Implementation Details |
Naming Conventions
Name your Functions, Types, etc. (Naming Conventions) |
Decide Between as_* vs to_* vs into_* for Conversion Methods |
Name Getters |
Name Iterators |
Use Keyword
Visibility
Contributing
API Documentation
Dev Container Docker
Dev Environment Setup
Development Editing
Preprocessors
Publication
Repo Structure
Folders and Key Files |
Book Organization |
Code Organization |
All Examples are Fully and Continuously Tested |
Topics of Interest
Crate: Selection
Language
Attributes
Closures
Closure Syntax |
Force Closure Capture by Value |
Annotate Closure Types |
Use Closures as Function Arguments |
Constants and Statics
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 |
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 |
Entrypoint
Define the Entry Point of your Application with the Main Function |
Define the Entry Point of your Asynchronous Application |
Enums
Functions
Write a Rust Function |
Write a Generic Function |
Return a Reference from a Function |
Work with Diverging Functions |
Work with Function Pointers |
Generics
Impl Trait
Simplify Method Signatures with impl Trait |
Return Opaque Types (esp. Closures and Iterators) with Return-position impl Trait |
Iterators
Lifetimes
Macros
Match
Ownership Borrowing
Ownership |
Move Semantics |
Clone (Deep Copy) |
Copy Semantics |
References and Borrowing |
Borrowing when Calling a Function |
Rust Install
Slices
Structs
Trait Objects
Traits
Variables
Links
Blogs
Chat Platforms, Forums, and Social Media |
Rust Blogs and Newsletters |
Personal Blogs |
Project and Organization Blogs |
Books
Companies
Example Code
Learning
Rust Overviews and Starting Points |
Learning Roadmaps |
Tutorials and Workshop Materials |
Guides |
Courses |
University Courses |
Ferrous Systems Training |
Paid Courses |
Others |
Meetings
Rust Cheatsheets
Videos
Standard: Library
AsRef
Recipe | Crates |
---|---|
Accept Arguments of Multiple Types with AsRef | |
Use as_ref to Get a Reference to the Contained Value of a Smart Pointer | |
AsRef vs. Deref vs. Borrow |
Borrow
Recipe | Crates |
---|---|
Borrow Trait | |
Differences between Borrow , Deref , and AsRef in Generic Code | |
Implement Borrow for a Custom Type |
Box
Recipe | Crates |
---|---|
Store Data on the Heap with Box | |
Box Use Cases | |
Use Box to Store Dynamically Sized Types | |
Implement Recursive Data Structures with Box | |
Use Box as a Smart Pointer to Owned Trait Objects |
Cmp
Recipe | Crates |
---|---|
Test for Equality with PartialEq and Eq | |
Compare and Sort Values with PartialOrd and Ord |
Conversion Traits
Cow
Default
Recipe | Crates |
---|---|
Define Default Values for a Struct with Default |
Derive
Drop
Dynamic Typing
Interior Mutability
Ops
Option
Pin
Reference Counting
Recipe | Crates |
---|---|
Share Ownership of a Value with Rc | |
Share Ownership of a Value with Interior Mutability via Rc and RefCell | |
Share Ownership of a Value with Rc |
Result
Recipe | Crates |
---|---|
Handle Recoverable Errors with Result | |
Retrieve or Transform Values in Result | |
Get Reference to Values Inside a Result | |
Result vs Option |