Bart Massey 2021
Various small examples from my Rust course. Previously a lot of these were on the playground, but I prefer to have them in a controlled repository now.
datatypes/
: examples of various datatype thingiesstructs.rs
: struct and enum examplesarrays.rs
: array and vector examplesstrings.rs
: string and str examplesiterators.rs
: iterator examplesclosures.rs
: closure exampleslifetimes.rs
: simple lifetime examplerc/
: examples withRefCell
andRc
readline/
: example of readline with error handlingerror/
: example of creating a custom errormodules/
: example of modulespoint.rs
: example of "methods" and ownershipunits.rs
: example of newtype and derivingpatmove.rs
: example ofref
in patternsresult/
: example of defining and usingResult
top.rs
: top-n list example using genericssum.rs
: generic iterator sum examplecustom_sum.rs
: sum example with customSum
typeaddy.rs
: trait def/impl examplebno-salad.rs
: trait salad example from Blandy and Orendorffmatmul.rs
: example of overloading multiplication for matricesstacks.rs
: example defining a stack traitphantom.rs
: phantom type examplederef.rs
: deref trait examplefrom.rs
: from / try_from trait exampleprog.rs
,prog2.rs
: state machine examples using closuresnegiter/
: example iterator adapterstackcoll/
: example fromiterator implementationshuflr/
: example iterator implementationseqs.rs
: examples with sequence typesvecdeque.rs
: example ofVecDeque
usagesetimpl.rs
: example implementation ofHashSet
asHashMap
rng/
: example use ofrand
cratecharcast.rs
: character / number casting exampleslower.rs
: boring character lowercase examplestringchars.rs
: string ←→ chars conversion examplesstdio.rs
: stdio usage exampledebug-macro.rs
: declarative macro examplesquare-macro.rs
: example of macro argument reusemacro-body-bug.rs
: example of syntax issue in macro bodydebug-macro-rep.rs
: example of macro with varargsmacro-nargs.rs
: example of recursive macromacro-tt.rs
: macro token tree examplenullptr.rs
: null pointer examplec++-ffi/
: example of FFI between C, C++ and Rustownership-demo/
: example of ownership and borrowing stuff in C and Rustrust-winter2022/
: examples from Rust class Winter 2022struct-example.rs
: example of Rust structenum-example.rs
: example of Rust enumclosure-example.rs
: example of Rust closureiterator-example.rs
: example of Rust iteratorlifetimes-example.rs
: example involving Rust lifetimesstrref.rs
: example involving Rust string clones and copiesclosures/
: closure examplesfor-demo.rs
: example of passing iteratorsiter-from-fn.rs
: example use ofiter::from_fn()
rev.rs
: examplefor
loop with reversed iterator