Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

RustbeginnercliAI generated

Hex Dump Explorer

Build a hex dump tool in Rust, like the classic xxd or hexdump commands. It reads any file, even a picture or a program, and shows its bytes as rows of hexadecimal numbers alongside their printable text, with the byte offset at the start of each row. You can choose where to start, how many bytes to show and how many bytes appear per row, and highlight a byte pattern you're looking for. It's a great beginner Rust project for understanding what files really contain: you'll learn reading files in chunks, formatting numbers in hexadecimal, handling command-line arguments with clap, error handling with Result, and writing tests.

Estimate
~7h
Steps
5
Completed by
0
Proposed by
codeseed.app

Cargo · clap

Project roadmap

  1. 01

    Create the project and arguments

    ~1h

    Run cargo new hexview and add clap with the derive feature. Define the arguments: a file path, --offset (where to start, default 0), --length (how many bytes to show, default everything) and --width (bytes per row, 8, 16 or 32, default 16). Parse offset and length in decimal or in hex with a 0x prefix. Done when: hexview --help lists the options, and an invalid width is rejected.

  2. 02

    Read the file in chunks

    ~1.5h

    Open the file, seek to the offset with Seek::seek, and read width bytes at a time into a buffer with a BufReader, stopping at the end of the file or after length bytes. Show clear errors for a missing file, a directory, or an offset beyond the end of the file. Never read the whole file into memory. Done when: the program reads the requested part of a test file row by row.

  3. 03

    Format each row

    ~1.5h

    Write format_row(offset, bytes, width) -> String that returns a line with: the offset as 8 hex digits, the bytes as two-digit hex values separated by spaces, with an extra space in the middle of the row, padded so a short last row stays aligned, and the ASCII text between | characters, where non-printable bytes are shown as a dot. Done when: the output for a test file looks like xxd's.

  4. 04

    Highlight a pattern

    ~1.5h

    Add --find with a hex byte pattern such as "de ad be ef" or a text string with --find-text. Highlight matching bytes with ANSI colors, including matches that span two rows, and print the offsets of all matches at the end. Add --no-color, and disable colors automatically when the output isn't a terminal. Done when: searching for a known string in a test file highlights it and lists the right offsets.

  5. 05

    Write tests

    ~1.5h

    Write unit tests for format_row (a full row, a short last row, non-printable bytes, different widths) and integration tests that run the tool on small files created in the test with the tempfile crate, checking offsets, length limits and pattern matches. Done when: cargo test passes.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~7h · 5 steps

Tech stack

Cargoclap