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.
rustlings-exercises-completed/README.md

45 lines
1.5 KiB
Markdown
Raw Normal View History

2015-09-14 21:32:54 -05:00
# rustlings
2018-04-26 14:21:28 -05:00
A cool thing that is currently in development.
2015-09-14 21:32:54 -05:00
2018-05-22 13:59:50 -05:00
## 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:
```rust
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.
2018-05-22 15:27:51 -05:00
The tests themselves can generally be structured in whatever way is desired, there doesn't have to be a "tests" module, for example. Two macros are provided
for convenience. The `verify` helper function is essentially a specialized `assert_eq!`, but it doesn't panic
2018-05-22 13:59:50 -05:00
if the values mismatch, instead it prints out a helpful error message and keeps going. The
2018-05-22 15:27:51 -05:00
`verify_easy` function is designed as a drop-in replacement for the `verify` function for if the learner needs help solving the exercise. It prints the expected value, too.
2018-05-22 13:59:50 -05:00
2018-05-22 14:03:19 -05:00
This is roughly what the console output for a simple exercise looks right now:
![](https://i.imgur.com/gGgjvLW.png)
2018-05-22 13:59:50 -05:00
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.