To run the examples follow the steps:
- Install
rustup
environment (if not set up yet), see https://www.rust-lang.org/learn/get-started for more details. - Clone or download the repository.
- Enter the main directory:
cd rust-lecture-examples
- Run a chosen example:
cargo run --example <example_name>
- If an example contains unit tests, you can run them using:
cargo test --example <example_name> -- --nocapture
The nocapture
option allows to print test output (written using println!
macro) to the terminal.
- If you want to run particular test specify its name:
cargo test --example <example_name> tests::<test_name> -- --nocapture
for example:
cargo test --example smart-pointers tests::refcell_interior_mutability -- --nocapture
The complete list of examples you will find in examples
directory.
Here's the (incomplete yet) description of the examples:
smart-pointers.rs
illustrates how to use types such asBox
,Rc
andRefCell
;static-dispatch-benchamrk.rs
anddynamic-dispatch-benchmark.rs
provides a simple benchmark comparing static and dynamic dispatch; to see the proper result run them with:cargo run --example static-dispatch-benchmark.rs --release