mediatypes
A comprehensive collection of MIME types (media types) as string constants for Rust.
This crate provides an organized, hierarchical structure of all standard MIME types registered with IANA, making it easy to reference media types in a type-safe manner without hardcoding strings throughout your application.
Features
- Comprehensive: Includes all major MIME types from the IANA registry
- Zero dependencies: No external dependencies required
- Type-safe: Constants prevent typos in MIME type strings
- Well-organized: Grouped by top-level media type for easy navigation
- Fully documented: Every constant includes the actual MIME type string
- No unsafe code: Built with
#![deny(unsafe_code)]
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
use application;
use image;
use text;
use video;
// Use in HTTP headers
let content_type = JSON; // "application/json"
// File upload handling
match file_extension
// API responses
response.header;
// Form data
let form_type = WWW_FORM_URLENCODED; // "application/x-www-form-urlencoded"
Organization
MIME types are organized by their top-level type into separate modules:
application- Application-specific data (JSON, XML, PDF, ZIP, etc.)audio- Audio formats (MP3, WAV, OGG, FLAC, etc.)font- Font formats (TTF, OTF, WOFF, WOFF2, etc.)image- Image formats (PNG, JPEG, GIF, SVG, WebP, etc.)message- Message protocols (RFC822, HTTP, SIP, etc.)model- 3D model formats (GLTF, OBJ, STL, etc.)multipart- Multi-part messages (form-data, mixed, etc.)text- Human-readable text (HTML, CSS, JavaScript, plain text, etc.)video- Video formats (MP4, WebM, MPEG, etc.)
Examples
Web Server Response
use ;
API Client
use application;
async
Form Handling
use ;
Contributing
Contributions are welcome! If you notice any missing MIME types or have suggestions for improvements, please open an issue or submit a pull request.
License
This project is licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Acknowledgments
MIME types are based on the IANA Media Types registry.