about
Rust Track Summary
7/25/2023
Rust Bites Docs RustBites Code RustStory Code

Rust Track Summary

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 Motivation 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
"What I have been learning ... was not Rust in particular, but how to write sound software in general, and that in my opinion is the largest asset that the rust community taught me, through the language and tools that [they] developed."
- Jorge Leitao on rust-users

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. Rust Highs and Lows

Table 1. Rust Resources from this site

ResourceContents
Rust Repositories Index of all the Rust code repositories
Rust Story
Index at upper right on this page.
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
first Rust Bite - Rust highs & lows <-- good place to go after this page
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

The code above on the right illustrates a function with side affects, something you rarely want to implement, but its a nice example of how the Rust object model works. Callers see changes made by the function to the string value held by the Box smart pointer. Because the argument is a reference type, passed by reference, caller's also see a change to the target object, should the function do that. The change happens at line 29. Boxes release their resources when they go out of scope, so there is no resource leak here. Note that this code is easier to understand than the C++ example given in the C++ Track page. Normally we would pass in a non-mutable reference and return the modified instance by value. Rust effects that with a move operation for non-copy types. I chose this example because it illustrates a part of the Rust object model. This page is focused on pointing to discussions of Rust models and code examples. It has most of the things you will need to start Rust programming quickly.

Table 2. - Rust Code Examples

Topic 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
 
After writing your first few programs, it is likely that resources in Tables 2 and 3 will speed up your progress understanding and using Rust and C++. Table 3 contains intermediate to advanced materials written in plain language.
 

Table 3. - Other Resources

Topic Content
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
 
You can find videos covering some of the topics in Table 1. and Table 2. using the "Videos" link in the top menu. First Rust Bite is a good next step after this page.

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".
  Next Prev Pages Sections About Keys