mime
Strongly typed MIME (HTTP Media Type) parsing and construction for Rust
Repository Health
Technical Analysis
mime is a small Rust crate that models MIME (HTTP Media Type) values as strong types rather than raw strings, catching malformed content-type values at compile time or parse time instead of deep in a request handler. It is a foundational dependency across the Rust HTTP ecosystem, used by libraries like hyper and actix-web to represent Content-Type and Accept headers without repeated ad-hoc string splitting.
The crate exposes constants for common types (mime::TEXT_PLAIN, mime::APPLICATION_JSON) plus a parser for arbitrary media type strings, letting consumers pattern-match on type/subtype pairs and query parameters (like charset) safely.
What You Get
- A
Mimestruct with strongly typed top-level type and subtype accessors - Predefined constants for common media types (TEXT_PLAIN, APPLICATION_JSON, IMAGE_PNG, and more)
- A conformant parser for arbitrary MIME strings per RFC 7231
- Support for MIME parameters such as
charsetviaget_param - Optional serde support for serializing/deserializing Mime values
Common Use Cases
- Parsing and validating a Content-Type header in an HTTP server or client
- Building Accept headers or content negotiation logic that matches on type/subtype
- Storing and comparing file/attachment media types without manual string handling
- Underpinning higher-level HTTP crates (hyper, actix-web) that need a canonical MIME representation
Under The Hood
Architecture - The crate splits parsing logic into a mime-parse sub-crate consumed by the top-level mime crate, which layers ergonomic constants and accessor methods (type_(), subtype(), get_param()) over the parsed representation, keeping the public surface small (src/lib.rs, src/type_.rs, src/value.rs) while isolating RFC 7231 grammar handling. Tech Stack - Pure Rust with zero required runtime dependencies beyond quoted-string for parameter parsing; an optional serde1 feature adds serde Serialize/Deserialize support and an optional macro feature (via mime-macro and proc-macro-hack) enables compile-time-checked MIME literals; Cargo workspace groups the root crate with mime-macro and mime-parse. Code Quality - Unit tests live alongside implementation in constants.rs, value.rs, type_.rs, macros.rs, and range.rs, exercising parsing edge cases and equality/ordering behavior; the codebase is small (~1,200 lines across core files) and has been stable for years with infrequent but low-risk maintenance commits. API Design - The API favors compile-time constants (mime::TEXT_PLAIN) for the common path and a parse() fallback for arbitrary strings, minimizing boilerplate for typical HTTP header handling; documentation lives on docs.rs with a concise README usage example.
Used by 8 apps in this directory
AppFlowy
Productivity · Project Management · Collaboration
The open-source AI workspace that puts your data, your rules — with local LLMs, CRDT collaboration, and full self-hosting built in.
Hoppscotch
Developer Tools
A lightweight, offline-capable API development ecosystem for testing HTTP, GraphQL, WebSocket, MQTT, and SSE endpoints across web, desktop, and CLI.
Huly Platform
Project Management · Team Chat · Collaboration
Open-source all-in-one workspace that replaces Linear, Jira, Slack, and Notion for product and engineering teams.
InfluxDB
Databases · Analytics
Open-source time-series database built for real-time ingest, fast SQL queries, and embedded Python automation — powered by Apache Arrow and Parquet.
Lemmy
Community · Social Media
Federated, self-hosted Reddit alternative with full community ownership and no corporate control.
Lokus
Note Taking · Knowledge Management
Local-first note-taking with graph view, canvas & AI plugins—your Markdown files, zero telemetry, blazing-fast Rust performance.
Meilisearch
Search
Lightning-fast hybrid search engine with AI-powered semantic and full-text retrieval for modern applications.
Stalwart
Collaboration
All-in-one secure mail and collaboration server covering IMAP, JMAP, SMTP, CalDAV, CardDAV, and WebDAV in a single memory-safe Rust binary.