explaingit

rust-bakery/nom

10,390RustAudience · developerComplexity · 3/5Setup · easy

TLDR

A Rust library for building parsers by composing small reusable functions, no grammar files, no code generation needed. Works on binary data, plain text, and streaming input that arrives in chunks.

Mindmap

mindmap
  root((nom))
    Approach
      Parser Combinators
      No Code Generation
      Pure Rust
    Input Types
      Binary Data
      Plain Text
      Streaming Chunks
    Use Cases
      File Format Parsers
      Network Protocols
      Config Languages
    Features
      Custom Errors
      Zero-copy Slices
      Rust 1.65 Plus
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Parse a custom binary file format in Rust by combining small, independently testable parsing functions.

USE CASE 2

Build a streaming network protocol parser that handles data arriving in chunks without producing wrong results mid-stream.

USE CASE 3

Write a parser for a configuration language like TOML in pure Rust without a separate grammar file or code generator.

USE CASE 4

Build a prototype compiler front end by composing nom combinators to tokenize and parse source code.

Tech stack

Rust

Getting it running

Difficulty · easy Time to first run · 30min
No license information is mentioned in the explanation.

In plain English

nom is a library for writing parsers in the Rust programming language. A parser, in this context, is a piece of code that reads raw data and extracts structured information from it. For example, a parser might read a chunk of bytes and recognize that it contains an HTTP request, a JSON document, or a custom binary file format. Instead of requiring you to write grammar files in a separate language and run a code generator, nom takes a different approach called parser combinators. You build small, focused functions that each handle one tiny task, such as "match the word HTTP" or "read exactly four bytes", and then combine them into larger parsers. The resulting code stays in Rust, can be tested piece by piece, and closely mirrors what the format actually looks like. nom works on binary data, plain text, and streaming input. For streaming, it is designed to handle situations where data arrives in chunks rather than all at once, such as network traffic or large files. If there is not enough data yet to make a decision, nom signals that it needs more rather than producing a wrong result. It also avoids copying data wherever possible, returning slices of the original input instead of allocating new buffers. The library has been used to build parsers for HTTP, video containers like FLV and Matroska, archive formats like tar, configuration languages like TOML, and prototype programming language compilers. It supports custom error types so that when a parse fails, you can report the exact location and reason rather than a generic failure message. nom is available as a package on crates.io, the standard package registry for Rust, and works with Rust version 1.65.0 or newer. Documentation, a beginner guide called the Nominomicon, and a list of available combinators are all linked from the repository.

Copy-paste prompts

Prompt 1
I'm using nom in Rust to parse a binary protocol where each message starts with a 2-byte length prefix followed by that many bytes of payload. Show me the complete nom parser for this.
Prompt 2
How do I handle streaming input in nom where data arrives in chunks? Show me an example with a simple line-delimited text protocol.
Prompt 3
I need to parse an HTTP request line (method, URL, HTTP version) using nom. Give me the complete parser with error handling.
Prompt 4
Walk me through writing a nom parser for a config file format where each line is 'key = value' and lines starting with '#' are comments.
Prompt 5
How do I add custom error messages to a nom parser so that when parsing fails, I can report exactly what went wrong and at which byte offset?
Open on GitHub → Explain another repo

← rust-bakery on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.