Expand description
§solution is a helper to generate solution of exercise
§Quick start
cargo add solutionAdd a solution feature in your crate.
[package]
name = "exo01"
[features]
solution = []
[dependencies]
solution = { version = "0.1.0" }And use solution!() and/or solution_type macro, e.g.:
use solution::{solution,solution_type};
/// this struct should be removed
struct WhichType;
fn variable_strip_prefix(string: solution_type!(&str)) -> Option<solution_type!(WhichType => &str)> {
solution!({
string.strip_prefix("$")
})
}
fn main() {
for arg in std::env::args().skip(1) {
solution!(hint = "remove the optionnal '$' at start and display environment variable", {
let name = variable_strip_prefix(&arg).unwrap_or(&arg);
println!("{name} = {}", std::env::var(name).expect("404 variable not found"));
})
}
}Now you can build student version with cargo build (but depends which you have write in solution_type!() it can be unable to build) and teacher version with cargo build -F solution.
§Generate student version
cargo install solution_cli
solution --source <teacher_directory> generate <student_directory>The last command generate new rust file in <student_directory> :
ⓘ
use solution::{solution,solution_type};
/// this struct should be removed
struct WhichType;
fn variable_strip_prefix(string: /* TODO: */ _) -> Option</* TODO: */ WhichType> {
todo!()
}
fn main() {
for arg in std::env::args().skip(1) {
todo!("remove the optionnal '$' at start and display environment variable")
}
}
Macros§
- _fake_
or_ real_ block - _fake_
or_ real_ ty - solution
- Add solution to a problem
- solution_
type