Use this small Rust 2021 CLI to spot tab characters in saved text. It accepts one file path or `-` for standard input, validates the complete input as UTF-8, and prints a concise report. Its focus on tab locations is distinct from general line counts, word lengths, first-character grouping, and line-ending audits.
Before you start
- Use only the Rust standard library; no external crates, unsafe code, include macros, environment variables, subprocesses, networking, or filesystem writes.
- Accept exactly one CLI argument: a UTF-8 file path or `-` for stdin.
- Read input without modifying or executing it, and reject invalid UTF-8 instead of silently replacing or truncating bytes.
- Count every tab character and report one-based line numbers for lines containing tabs.
- Write the report to stdout and actionable failures to stderr; use a nonzero exit status for failures.
- Use Rust 1.90.0 with edition 2021 as the intended runner, without claiming a tested minimum version.
Build and check
- Save the single-file program as `recipe.rs`.
- Compile it with `rustc --edition=2021 recipe.rs -o recipe`.
- Run `./recipe path/to/saved.txt` to audit a file, or `./recipe -` and provide text on standard input.
- Check stdout for total tab count, affected-line count, and one-based line numbers; check stderr if the command reports a failure.
Limits to understand
- The program reads the entire input into memory before validating UTF-8 and producing results.
- Line numbers are based on splitting at LF; a final LF creates an empty final segment, which cannot contain a tab.
- The tool only counts the literal tab character U+0009; it does not infer visual indentation or expand tabs.
- The input is treated as data only; this program does not parse document formats or interpret commands.
- Invalid-byte rejection requires a fixture containing raw invalid UTF-8 bytes. JSON text fixtures alone cannot demonstrate this case.
What this example adds
No upstream implementation was supplied, so no upstream code was adapted. The task is a focused tab-location audit: it counts tab characters and identifies affected one-based lines, rather than summarizing general line properties. The implementation reads the selected source fully, validates UTF-8 before reporting, handles file and stdin errors explicitly, and keeps diagnostics off stdout.
Run it
Intended runner: Rust 1.90.0, edition 2021. Save the code as `recipe.rs`, then compile with `rustc --edition=2021 recipe.rs -o recipe`. Run `./recipe <file-path>` or use `./recipe -` to read standard input. Exactly one argument is required. A file is only opened for reading. Actionable usage, I/O, and UTF-8 errors are printed to stderr with a nonzero exit status.Example input
Synthetic stdin text, with a literal tab between `alpha` and `beta`:
alpha beta
plain
x y z
Expected output
tabs: 3
lines_with_tabs: 2
line_numbers: 1,3

