solution is a helper to generate solution of exercise
Quick start
cargo add solution
Add 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};
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};
struct WhichType;
fn variable_strip_prefix(string: _) -> Option< WhichType> {
todo!()
}
fn main() {
for arg in std::env::args().skip(1) {
todo!("remove the optionnal '$' at start and display environment variable")
}
}