A copy of my code from when I was doing the Rustlings exercises. https://github.com/rust-lang/rustlings
This repository has been archived on 2023-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
2018-05-22 20:59:50 +02:00
old_curriculum move old files to a separate directory 2018-04-26 21:29:11 +02:00
src rustfmt 2018-05-16 15:30:30 +02:00
.gitignore init new cargo project 2018-04-26 21:41:19 +02:00
Cargo.toml experiment 2018-05-06 18:59:50 +02:00
LICENSE Update LICENSE year. 2016-03-27 15:57:49 -04:00
README.md add some basic docs 2018-05-22 20:59:50 +02:00

rustlings

A cool thing that is currently in development.

How it's structured

Ideally, like RubyKoans, all exercises can be run by executing one command, in this case cargo run (most likely). This runs src/main.rs, which in turn runs all of the exercises. Each exercise is contained in a Rust file called about_<exercise topic>.rs. A minimal exercise looks somewhat like this:

fn exercise_function() {
  "hello"
}

mod tests {
  use super::*;
  
  pub fn test() {
    verify!("REPLACE ME", exercise_function(), "Function description");
  }
}

pub fn exec() {
  tests::test();
}

Each exercise file is supposed to have one exec function which gets called by the main.rs file. This function, in turn, calls all individual test functions.

The tests themselves can generally be structured in whatever way is desired. Two macros are provided for convenience. The verify! macro is essentially a specialized assert_eq!, but it doesn't panic if the values mismatch, instead it prints out a helpful error message and keeps going. The verify_easy! macro is designed as a drop-in replacement for the verify! macro for if the learner needs help solving the exercise. It prints the expected value, too.

Keep in mind that this is a very early draft of how things work. Anything here might be changed at any time, and this documentation should be updated accordingly.