RepoRust_RustBasicDemos.html
copyright © James Fawcett
Revised: 11/13/2025
Contents:
Basic demos for Rust syntax:
Some of these demos develop examples used in the Rust Story and will eventually be moved
to their own RustStory repository. The others are explorations I made while learning rust.
-
code_structure_demo
Demonstrates building an application out of several packages, one of which provides a
trait interface and object factory. That allows the other packages to avoid binding to
its implementation details.
-
data_types
Basic demos for ints, floats, char, bool, unit, arrays, tuples, Strings, structs, enums,
Vecs, and HashMaps
-
demo_library
Hello world library to show how applications can use modules and libraries.
-
demo_test
Shows how to load Hello World library package and import local hello module.
-
display library
Provides display helper functions and a log function that displays type and value of supplied
variable.
-
display_test
Tests display operations and also shows how to import local crate (display).
-
enum_probes
Example use of enumerations and matching.
-
error_probes
Using Option<T> and Result<T, E> enumerations.
-
file_io
Illustrates reading from files. Will add file writing soon.
-
function_probes
Demonstrates pass by value and reference, passing functions as arguments.
-
generics_probes
Illustrates generic functions and structs.
-
iterator_probes
Iterator and iterator adapter example use.
-
lambda_probes
Examples of closure uses.
-
logger
First example of a fairly complete application.
-
rust_modules
Demonstrates how to assemble a crate and external modules it depends on.
-
rust_probes
- small, getting started demos. First code I wrote in Rust to learn the language basics.
-
dblformats - shows how to format double precision numbers
-
debugformats - illustrates what debug formats {:?} do for each of the Rust types
-
demodrop - first take on ownership
-
env_probe - extract and display command line
-
formatstructure - various ways to use the format specifiers
-
ownership - thorough walkthru of ownership: copy, move, and references (borrows)
-
point_traits - explores using traits with generic structs, static and dynamic dispatching
-
probe_structs - ownership and traits
-
probe_traits - explore using traits as interfaces and generic type constraints
-
probe_unsafe - quick peek at unsafe blocks and use of safe pointers
-
types - complete illustration of declaration specifiers for each of the Rust types
then contrasts with type deduction
-
string_probes
Indexing is an issue for Rust Strings since char type is utf8, e.g.,
variable size characters. Note that indexing strings of utf8 chars is inherently order n.
-
struct_probes
Using structs as types with methods and traits.
-
vector_probes
A few simple demos of vectors and ownership.
Build:
This Rust code was built with Cargo from Visual Studio Code terminal and tested on Windows 10.
Status:
There is some overlap of demo code in these examples. I will refactor once the Rust Story is
complete.