| Crates.io | solution_cli |
| lib.rs | solution_cli |
| version | 0.1.1 |
| created_at | 2025-12-12 15:28:11.552479+00 |
| updated_at | 2025-12-12 16:14:43.410313+00 |
| description | CLI for convert crate use `solution::solution!()` macro to a version for student (with solution stripped and hint in `todo!()`) |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1981719 |
| size | 33,026 |
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};
/// 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.
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")
}
}