Skip to main content

Crate use_mime

Crate use_mime 

Source
Expand description

§use-mime

Small MIME type utilities for RustUse.

§Experimental

use-mime is experimental while the use-web workspace remains below 0.3.0. Expect small API adjustments during the first release wave.

§Example

use use_mime::{is_json_mime, mime_from_extension, parse_mime};

let mime = parse_mime("application/ld+json; charset=utf-8").unwrap();

assert_eq!(mime.type_, "application");
assert_eq!(mime.subtype, "ld");
assert_eq!(mime.suffix.as_deref(), Some("json"));
assert_eq!(mime_from_extension("svg"), Some("image/svg+xml"));
assert!(is_json_mime("application/ld+json"));

§Scope

  • Lightweight MIME parsing and classification.
  • Small extension and MIME lookup tables for common web assets.
  • Graceful handling for malformed input.

§Non-goals

  • Complete IANA MIME coverage.
  • Content sniffing.
  • File parsing.

§License

Licensed under either of the following, at your option:

  • Apache License, Version 2.0
  • MIT license

Structs§

MimeType
A lightweight MIME type split into type, subtype, and optional suffix.

Functions§

extension_from_mime
Returns a common extension for the requested MIME type.
is_css_mime
Returns true when the MIME type is CSS.
is_html_mime
Returns true when the MIME type is HTML.
is_image_mime
Returns true when the MIME type is image-based.
is_json_mime
Returns true when the MIME type is JSON or a +json subtype.
is_text_mime
Returns true when the MIME type is text-based.
is_xml_mime
Returns true when the MIME type is XML or a +xml subtype.
looks_like_mime
Returns true when the input parses as a MIME type.
mime_from_extension
Returns a common MIME type for the requested extension.
parse_mime
Parses a MIME type essence into simple parts.