Rust Command-Line Tools
Project workbook ยท Path 81

Design a Rust command-line parser that accepts valid positive quantities and returns informative errors for invalid input.

The case

A fictional packing tool accepts quantities as command-line strings. Values must be integers from 1 to 99. For inputs 3, 7 and 10 the total is 20; a malformed or out-of-range input rejects the whole calculation. No files are modified.

Input setExpected behavior
3 7 10total 20
3 x 10error; no total
0 2error; no total
99 1total 100
STAGE 1

Learn the relevant Rust foundations

Use the course navigation to study the foundations needed for a small parser. Distinguish owned strings from borrowed string slices. You do not need unsafe code or concurrency for this case. Keep the exercise scope small enough to understand every conversion and error path.

Your task

Write a function signature that accepts a slice of string inputs and returns a Result.

Required output

Parser contract

Record your result and evidence here or in a separate file.

Review gate

The result type makes failure explicit.

If the gate is not met

Avoid adding lifetimes or generics without a demonstrated need.

STAGE 2

Handle recoverable errors

Parsing external input can fail normally. Propagate or map the parse error into a message that names the invalid argument without crashing. Then check the business range separately. A successful parse of zero is still invalid under the case rule. The official Rust book supplies a focused supplementary explanation.

Your task

Implement parse-and-range validation for one quantity.

Required output

Quantity parser

Record your result and evidence here or in a separate file.

Review gate

Malformed text and out-of-range integers return errors.

If the gate is not met

Keep parse failure distinct from range failure.

STAGE 3

Aggregate only a valid set

The case uses all-or-error behavior: any invalid argument prevents a total from being reported. Choose an integer type wide enough for the intended sum and document limits. A command-line adapter can print the successful total or an error and nonzero exit status without mixing the core logic with output formatting.

Your task

Implement total_quantities and a small command-line adapter.

Required output

Command-line source

Record your result and evidence here or in a separate file.

Review gate

3, 7, 10 produce 20; an x input produces no success total.

If the gate is not met

Return early on an error instead of replacing it with zero.

STAGE 4

Write behavior checks

Test valid boundaries, malformed input, an empty argument list and a rejected range. Expected results should be written before execution. This preparation environment has no Rust compiler or Cargo, so the source and checks are provided for a real local run; no compiled binary is claimed.

Your task

Run cargo test locally when available and retain the actual output.

Required output

Rust tests and execution record

Record your result and evidence here or in a separate file.

Review gate

Expected output is clearly separated from actual run evidence.

If the gate is not met

Do not label source inspection as a compiler pass.

STAGE 5

Document a usable interface

A command-line tool needs usage syntax, exit behavior and examples. Explain whether an empty input is allowed; this case rejects it because there is no quantity to summarize. Keep error messages actionable and do not expose unrelated system data. Document that the program reads arguments only and writes no files.

Your task

Write a README with valid and invalid command examples.

Required output

Tool handoff

Record your result and evidence here or in a separate file.

Review gate

The usage examples agree with the implemented argument rules.

If the gate is not met

Reconcile the README and test expectations.

Final project

Deliver the source, tests, usage guide and actual local run log when a Rust toolchain is available. Add an input containing whitespace and state whether trimming is accepted.

Critical condition

Invalid input cannot produce a success total, and no unperformed Rust execution is claimed.

CriterionPointsEvidence
Evidence and correctness30Calculations, source use and results match the supplied case; limitations are honest.
Required artifacts30All five stage outputs and the capstone handoff are present and inspectable.
Reasoning and decisions20Choices, assumptions, alternatives and the case-specific critical condition are explained.
Reproducibility10A reviewer can follow the stated steps and distinguish expected from observed results.
Clear communication10Labels, units, structure and evidence references make the work easy to review.

Score at least 80/100, supply every required artifact, and satisfy the path-specific critical condition. Rework missing evidence before marking complete.

Worked reference

The valid set 3, 7, 10 totals 20. The set 3, x, 10 returns an error rather than 13. Values 1 and 99 are valid individually; 0 and 100 are not. Rust compilation and test execution remain local learner checks in this package.

Boundaries

This is a small local parser, not a compiled distribution or a production command-line package.