This repository contains hands-on examples and labs for building command-line tools with Rust for data engineering tasks. A Coursera course from Pragmatic AI Labs.
This repository has example projects in ./examples and hands-on labs in ./labs. Make sure you have the Rust toolchain installed.
This repository is Codespaces ready and set as a template repository. You can open it directly in a GitHub Codespace — Rust, rust-analyzer, and all extensions are pre-installed.
Complete these hands-on labs to reinforce your learning:
| Lab | Topic | Example |
|---|---|---|
| Lab 1: Your First CLI in Rust | std::env args, reading files, basic error handling | examples/1-first-cli |
| Lab 2: Using clap for Argument Parsing | clap derive API, named flags, help generation | examples/2-clap-intro |
| Lab 3: Organizing Code with Modules | mod, pub, separating business logic from main | examples/3-modules |
| Lab 4: Multi-Subcommand CLI Design | Subcommand derive, dispatch with match | examples/4-subcommands |
| Lab 5: Complex Argument Types | ValueEnum, Option, --limit, Box | examples/5-complex-args |
| Lab 6: Environment Variables | #[arg(env)], layered config, directory filtering | examples/6-env-vars |
| Lab 7: Logging | env_logger, RUST_LOG, info/warn/debug/error | examples/7-logging |
| Lab 8: Error Handling with anyhow | anyhow::Result, ?, bail!, ensure!, with_context | examples/8-error-handling |
- Reading command-line arguments with std::env
- Setting up the Rust toolchain and development environment
- Accepting files as input and handling basic errors
- Splitting logic into modules
- Using lib.rs and named module files
- Navigating crates.io and adding dependencies
- Multi-subcommand design with clap
- ValueEnum, optional paths, and --limit
- Environment variable configuration
- Subcommand design patterns for data workflows
- Creating a publishable Rust package
- Releasing to crates.io
- Containerizing a Rust CLI with Docker
- Structured logging with env_logger
- Error propagation with anyhow
- Replacing panics with user-friendly error messages
Wrapping up the course and next steps in the Rust for Data Engineering specialization.
Build datactl — a Rust CLI tool for data engineering tasks that reads CSV and JSON files and supports these subcommands:
read <file>— load a CSV or JSON file and show row count and column namessummary <file>— compute per-column aggregate statistics (count, min, max)filter <file> --column <name> --value <val>— print rows where the column matches the valueexport <file> --format csv|json [--output <path>]— convert between CSV and JSON formats
A starter implementation is in datactl/.
# Build
cargo build -p datactl
# Read a file
cargo run -p datactl -- read data.csv
# Summarize statistics
cargo run -p datactl -- summary data.csv
# Filter rows
cargo run -p datactl -- filter data.csv --column region --value west
# Export to JSON
cargo run -p datactl -- export data.csv --format json --output data.json
# Export to stdout
cargo run -p datactl -- export data.json --format csv-
Install the Rust toolchain:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-
Clone this repository:
git clone https://github.com/alfredodeza/rust-cli.git cd rust-cli -
Build the entire workspace:
cargo build --workspace
-
Run an example:
cargo run -p first-cli -- Cargo.toml
-
Run a subcommand example:
cargo run -p subcommands -- stats Cargo.toml
| Crate | Purpose |
|---|---|
| clap | CLI argument parsing with the derive API |
| serde / serde_json | JSON serialization and deserialization |
| csv | CSV reading and writing |
| anyhow | Ergonomic error propagation |
| log / env_logger | Structured logging controlled by RUST_LOG |
Coursera Courses