Skip to content

A set of links to playground examples that illustrate small bits of Rust syntax

Notifications You must be signed in to change notification settings

JimFawcett/RustPlaygroundExamples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RustPlaygroundExamples

Playground links to Rust syntax examples - see also:

Find all playground example code in the examples subdirectory. You can run any of these remotely with the included links
or locally with the command:
cargo run --example [name of example file omitting the rs extension]

ownership Ownership violations governed by use RustBites Ownership
copy and move primitive types are copied to new location, non-copy types are moved. RustBites Data
basic functions pass by value and by reference RustBites Functions
helper functions Illustrates displaying values and types using both concrete and generic functions with a useful set of helper functions.
closures Closures are function objects that operate on parameters and captures of local data. RustBites Functions
structs struct with constructor and methods RustBites structs
structs with defaults and clones struct with derived default and clone and struct with defined default and clone RustBites Generics and Traits
generic function and struct displays type using std::any::type_name RustBites traits
generic struct generic struct with bounds RustBites traits
struct copy and move Illustrates use (and non-use) of derived Copy trait RustBites Data
create many std::collection types create and display arrays, tuples, structs, vecs, vecdeques, hashmaps, strings, and strs RustBites Collections
str basic str operations RustBites Strings
String basic String operations RustBites Strings
iterating over strings iterating over ASCII and non-ASCII strings RustBites Iterators
String, str compares Equality comparison between strings using == operator
string conversions convert between String, &str, PathBuf, &Path RustBites conver
lifecycle using Box uses TestLifeCycle instance installed in Box to illustrate lifecycle and use of heap RustBites LifeCycle
functions accepting iterator explicit use of iterator in loop, implicit use with for loop RustBites Iterators
iterator for custom type custom type returns iterator over owned collection RustBites Iterators
custom iterator implement custom iterator for custom type RustBites Iterators
interation over collections iterating over array, String, Vec, VecDeq, and HashMap RustBites Iterators
RustBites DataStr
into_iter compares iter() with into_iter() RustBites Iterators
custom enumertion illustrates matching with custom enumeration RustBites Enum
non-enum matching matching chars: digit, lower case, uppercase, all else RustBites Enum
file error handling open for read, write, and read to string RustBites ErrHand
error bubbling illustrates file operations with error bubbling. The ErrHand link at the right explains how the bubbling process works using the "?" try operator. RustBites ErrHand
Lifetimes Result and Option wrapping &str so need lifetime annotation RustBites lifetime
RustBites options
plugin architecture plugin host holds Option of mutable reference to plugin - needs annotation. See options link at right for context: why you might chose this architecture. RustBites options
host owns plugin eliminate lifetime annotations in plugin architecture by moving plugin into host. See options link at right for advantages of host ownership. RustBites options
RegEx matching basic matching examples RustBites regex
RegEx Operations match, find, find_iter, and captures RustBites regex
interior mutability illustrates non-lexical scope analysis and run-time borrow checking with RefCell<T> RustBites Safety
interior mut with std::cell::Cells demos that show mutations with Cell<T> and RefCell<T> RustBites smartptrs
Basic Threads two threads mutably sharing atomic usize and std::output RustBites threads
sharing non-thread-safe value protected by Mutex<T> main and two child threads mutably sharing a string RustBites threads
ThreadResult<T> ThreadResult<T> is similar to C++ future: no hooks into async runtime. See link at right for details. RustBites threads

About

A set of links to playground examples that illustrate small bits of Rust syntax

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published