
Build a Disk Usage Analyzer in Rust Like du and ncdu
du walks a tree and adds up file sizes. The interesting decisions are hard links counted once, symlinks left alone and how to keep going when a directory is unreadable.
Everything you need to level up your coding skills.

du walks a tree and adds up file sizes. The interesting decisions are hard links counted once, symlinks left alone and how to keep going when a directory is unreadable.

A fuzzy finder reads lines, filters them as you type and prints the one you pick. The pieces are raw mode input, a matching engine and a small redraw loop.

pulldown-cmark turns Markdown into a stream of events, and its HTML writer renders them. A small CLI adds file handling, options and a page template around it.

A jq clone needs three parts: a parser for a small path language, an evaluator over serde_json values and a printer. The core is about 150 lines.

cargo-dist generates a release workflow that builds your binary for every platform, packages it and publishes installers when you push a version tag.

A log analyzer is a streaming pipeline: read lines, parse with a regex, fold into counters and print the top entries. Iterators keep memory flat on gigabyte files.

Read a file line by line with BufReader and reuse a buffer, or map it into memory with memmap2. Compare the options, the unsafe contract of mmap, and when reading in chunks is the safer and equally fast choice.

Use hyperfine to compare your CLI with grep, awk or a pipeline: warmup runs, prepare commands for cache control, parameter sweeps and export. Avoid the traps that make comparisons unfair.

Rust's regex crate guarantees linear-time matching, so there is no catastrophic backtracking. The real costs are compiling in a loop, unanchored scans and capture groups. Learn what to cache and when to use regex-lite.

Piping your Rust program into head makes println panic with Broken pipe. Rust ignores SIGPIPE, so handle the write error, or restore the default signal behavior in tools.

The regex crate guarantees linear time matching by leaving out backreferences and lookaround. See the API, the compile-once rule and what to use when you need the missing features.

Test a CLI end to end with assert_cmd and predicates: run the real binary, check the exit status, stdout and stderr, feed stdin and use temporary files.
We send one email when a new post is published. No spam.