| Crates.io | minimime |
| lib.rs | minimime |
| version | 1.0.0 |
| created_at | 2025-08-04 06:27:55.985854+00 |
| updated_at | 2025-08-04 06:27:55.985854+00 |
| description | A minimal MIME type detection library for Rust, ported from the Ruby minimime gem |
| homepage | https://github.com/XadillaX/minimime |
| repository | https://github.com/XadillaX/minimime |
| max_upload_size | |
| id | 1780387 |
| size | 238,601 |
A minimal MIME type detection library for Rust, ported from the Ruby minimime gem.
This library provides fast MIME type detection based on file extensions and content types, using embedded database files for efficient lookups without external dependencies.
Add this to your Cargo.toml:
[dependencies]
minimime = "1.0.0"
use minimime::{lookup_by_filename, lookup_by_extension, lookup_by_content_type};
// Look up by filename
if let Some(info) = lookup_by_filename("document.pdf") {
println!("MIME type: {}", info.content_type); // "application/pdf"
println!("Is binary: {}", info.is_binary()); // true
}
// Look up by extension
if let Some(info) = lookup_by_extension("json") {
println!("MIME type: {}", info.content_type); // "application/json"
}
// Look up by content type
if let Some(info) = lookup_by_content_type("text/css") {
println!("Extension: {}", info.extension); // "css"
}
lookup_by_filename(filename: &str) -> Option<Info> - Look up MIME type by filenamelookup_by_extension(extension: &str) -> Option<Info> - Look up MIME type by file extensionlookup_by_content_type(content_type: &str) -> Option<Info> - Look up by MIME content typeEach function returns an Info struct containing:
extension - File extension (without dot)content_type - MIME content typeencoding - Encoding typeis_binary() - Whether the file type is binaryThis library supports hundreds of file extensions and MIME types, including:
use minimime::lookup_by_filename;
fn main() {
// Check different file types
let files = vec![
"document.pdf",
"image.png",
"script.js",
"data.json",
"archive.zip"
];
for filename in files {
if let Some(info) = lookup_by_filename(filename) {
println!(
"{}: {} ({})",
filename,
info.content_type,
if info.is_binary() { "binary" } else { "text" }
);
}
}
}
use minimime::lookup_by_filename;
fn serve_file(filename: &str) -> String {
let mime_type = lookup_by_filename(filename)
.map(|info| info.content_type)
.unwrap_or("application/octet-stream".to_string());
format!("Content-Type: {}", mime_type)
}
fn main() {
println!("{}", serve_file("index.html")); // Content-Type: text/html
println!("{}", serve_file("style.css")); // Content-Type: text/css
println!("{}", serve_file("app.js")); // Content-Type: application/javascript
}
The library uses embedded hash maps for fast lookups, making it extremely efficient:
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.