Rust Track

Story, Bites, and Repositories

Story Index Prologue Introduction Models Models of structure and semantics Data Types & instances Operations Callable objects Structures Class structure Libraries Standard libraries References Resource links    
Bite Index Introduction Things to know about Rust Hello Rust Rust Hello World demo Rust Data Rust types and data demos Rust Objects Defining, creating, and using instances of Rust types Rust Generics Demo of generic types Rust Iteration Rust iterators, indexing, and enumeration Starting Samples and ideas Tooling VS Code, dev flow Safety Compiler enforcements Undef Behavior Causes Data Types, instance semantics FlashCards Type diagrams Facts Summary of types and basic ideas Strings String, str, other string types Data Structs Data structures Smart Pointers Box, Rc, Arc, RefCell LifeCycle Construction to Destruction Ownership Single ownership, borrowing Generics & Traits Definitions, examples Functions Functions and closures Structs Methods & Traits LifeTime Guarantee no dangling refs Abstractions Domain specific types Enumerations Collecting related types, matching Error Handling Result, bubbling Options Representing Some or None Conversions Converting between compatible types Collections Type diagrams Iterators Iterating over collections Idiomatic Code Clippy & API guidelines Macros Declarative macros Threads Threads, sharing, interior mutability Sync Thread synchronization with locks Channels Sending messages between threads Regular Expressions Using regex crate, string matching Hacks & Helpers Thread helpers, Date & Time Code Experiments Experimenting in playground Playground Examples Motivation Glossary Glossary of Rust terms    
Figure 1. Rust demo code
"Rust is a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety."
- Graydon Hoare, creator of Rust

Rust is a general-purpose programming language designed to provide memory and data race safety by contract. It does not use garbage collection and compiles to native code. Rust achieves memory safety by strictly enforcing a single ownership policy augmented with references that support mutability, with exclusive access during their lifetimes. It implements that with compile-time static analysis. Rust code also checks index bounds at run-time and terminates a thread responsible for attempts to access out-of-bounds indexes. Data race free operation is acheived with a combination of static checks to insure that references access data only via a Mutex or RWLock wrapper and runtime checks to ensure that only one mutable reference gets access within the lock. Rust safety details are dicussed in several of the Rust Bites in this Track. Rust development is an open-source project, supported by corporate doners that form the Rust Foundation. It's first stable release occured in 2015. The current edition, 2024, was released in January of 2025. There are five ways of viewing Rust content in this site:
  1. Rust Story
    An ebook with seven chapters that covers Rust programming at intermediate level.
  2. Rust Bites
    A large collection of pages each focused on one feature of the Rust programming language, starting with basics.
  3. Rust Code Repositories
    A collection of code for components, projects, and demonstrations.
  4. Blogs
    Some of the recent blogs focus on Rust specifics, with fairly complete coverage of a single topic in each.
  5. Rust Playground code examples
    Table of links to a collection of basic to intermediate code examples running in Rust Playground.
It's easy to sample each of these views by using the links above, or more selectively, using links in the RustExplorer panel on the left (if you don't see it, click on Toggle Panel button at bottom left).
What I like about Rust
The Rust language has some very interesting ideas about building memory and data-race safe programs. Program source compiles to native code and runs directly in the process created for it. Its safety mechanisms, enforced at compile-time, make getting started slower than for some other languages, but the compiler error messages are very good, making learning much easier as long as you understand Rust's basic models. The code above on the right illustrates a Rust "Hello World" function, often the first thing you encounter when learning a new language.

Table 1. Rust Resources from this site

Site Resources Content
Rust Repositories Index of all the Rust code repositories
Rust Tour Summary of features with screenshots and examples - pdf
Rust Models Summary of features with screenshots and examples - pdf
Rust Error Handling Summary with screenshots and examples - pdf
Rust Story
Rust ebook in 7 chapters
first chapter in Rust Story
Rust Bites
Index at upper right on this page.
Dozens of Code Bites about Rust
Rust Glossary Definitions of common terms
Rust FlashCards Basic types and data structures
Bits of Code Compares small C++, Rust, C#, Python, and JavaScript codes  
Rust Playground online compiler
Code Examples Content
Rust Repositories Index into Rust Repositories
Rust Code examples List of RustBites code examples, RustPlayground code examples, Rust Basic Demos Repository
online code execution RustPlayground, tutorialspoint
Other Resources Content
Rust Guide Definition and examples of Rust collections, iterators, and concurrency constructs.
Tooling Using Visual Studio Code to create and build Rust code
Rust home site Download and install, learn Rust
Rust user's forum Create an account and you can log-in, read, and post messages and questions.
The Rust Reference Semi-formal, but surprisingly readable, reference for Rust
Rust API Guidelines Guidelines for crafting Rust code, from the source
Other intermediate and advanced resources
How to learn modern Rust A collection of links to explorations of intermediate and advanced language materials
idiomatic rust resources Annotated links to articles and examples of community accepted styles and patterns for rust code.
 

Exercises

  1. Write a Rust program to find the largest file in a specified directory tree, using walkdir crate from crates.io.
  2. Ammend Project #1 by accepting arguments from the command line, using args crate.
  3. Use ChatGPT to create a directory traversal crate and use that instead of walkdir.
  4. Write a Rust program to read a source code file and count the number of lines and number of scopes for each function. You can count scopes by counting open braces "{". Start by searhing for fn and then read each line searching for "{" and "}". Push each open brace on a stack, and pop when a closed brace is encountered. When the stack is empty, the end of the function has been reached.
  5. Modify Project #4 by counting lines and scopes for each file in a directory tree rooted at a specified folder, usually named "src".