mime-infer
Infer MIME and media types from file extensions in Rust
Repository Health
Technical Analysis
mime-infer is a Rust crate that maps file extensions to their MIME/media types using a static, built-in lookup table. Given a path or filename, it returns the most likely content type, making it a lightweight building block for HTTP servers, static-file handlers, and upload processing.
Maintained under the Salvo project, it inspects only the extension portion of a path (never the file contents), so it is fast and allocation-free. When an extension maps to several plausible types, the crate returns them in priority order with the most correct one first.
What You Get
- Extension-to-MIME lookup backed by a static, maintained mapping table
- Support for extensions that resolve to multiple candidate types, ordered by correctness
- Zero file-system access: only the path string’s extension is inspected
- Integration with the mime crate’s typed MediaType values
- A small, fast dependency suitable for web servers and file tooling
Common Use Cases
- Setting Content-Type headers when serving static files
- Determining a media type for uploaded files by name
- Mapping file extensions to types in build or asset pipelines
- Providing default content types in a web framework’s file responses
Under The Hood
Architecture - The crate compiles a static table of extension-to-MIME mappings into the binary and exposes lookup functions that extract a path’s extension and return matching mime::Mime values. Because it never touches the file system, lookups are constant-time string matches, and extensions with multiple valid types return an ordered iterator with the preferred type first.
Tech Stack - Pure Rust targeting a minimum compiler version of 1.33, depending on the mime crate for typed media-type values. It is published to crates.io, documented on docs.rs, and tested via GitHub Actions.
Code Quality - As a fork within the Salvo ecosystem, it inherits a well-established mapping dataset and CI workflow. The README is explicit about correctness caveats, versioning tied to the mime crate, and the non-stable nature of returned types, showing careful attention to API contracts.
API Design - The surface is intentionally minimal: pass a path or extension, get back a media type or an ordered set of candidates. This narrow, single-responsibility API is trivial to adopt and hard to misuse, with clear documentation on how ties are broken.