accept-language
A tiny, dependency-free Rust library for parsing the HTTP Accept-Language header.
Repository Health
Technical Analysis
accept-language is a tiny Rust library for parsing and comparing the browser Accept-Language header. Given a raw header like en-US, en-GB;q=0.5, it returns the user’s languages sorted by quality preference, and its intersection helper matches those preferences against the locales your application actually supports to pick the best available language. It has no dependencies, is fuzz-tested on every change, and is designed to slot into any web server’s content-negotiation logic.
What You Get
- A
parsefunction that returns the header’s languages ordered by their quality (q) values - An
intersectionhelper that picks the best supported language given the user’s preferences - A zero-dependency, fuzz-tested implementation with a documented, minimal public API
Common Use Cases
- Deciding which translated content or locale to serve a visitor based on their browser settings
- Adding language negotiation to a Rust web service without pulling in a heavy i18n framework
- Normalizing and ranking language tags from incoming requests for downstream logic
Under The Hood
Architecture - The entire library lives in a single src/lib.rs of roughly 370 lines. parse tokenizes the header, extracts each language tag and its optional q weight, and returns the tags sorted by descending preference; intersection filters those parsed preferences against a caller-supplied list of supported languages to return the best matches in order. Tech Stack - It targets the Rust 2018 edition and has no runtime dependencies at all, keeping compile times and the dependency tree minimal. Code Quality - Correctness is backed by inline unit tests plus continuous fuzz testing with cargo-fuzz on every push and pull request via GitHub Actions, and there are benchmarks under benches/ to guard performance. API Design - The surface is just two free functions with obvious signatures, so integrating it is a matter of a single call in a request handler; the docs on docs.rs cover both functions with runnable examples.