# MediaType MIME Media-type parsing for Rust [![Crates.io](https://img.shields.io/crates/v/mediatype.svg)](https://crates.io/crates/mediatype) [![GitHub license](https://img.shields.io/github/license/picoHz/mediatype.svg)](https://github.com/picoHz/mediatype/blob/main/LICENSE) [![Rustdoc](https://img.shields.io/badge/doc-rustdoc-green.svg)](https://docs.rs/mediatype) ![Rust](https://github.com/picoHz/mediatype/workflows/Rust/badge.svg)

This crate provides two MediaType structs: MediaType and MediaTypeBuf.

MediaType

This does not copy data during parsing and borrows the original string. It is also const-constructible.

```rust use mediatype::{names::*, MediaType, Value};

let mut multipart = MediaType::new(MULTIPART, FORM_DATA);

let boundary = Value::new("dyEV84n7XNJ").unwrap(); multipart.setparam(BOUNDARY, boundary); asserteq!( multipart.to_string(), "multipart/form-data; boundary=dyEV84n7XNJ" );

multipart.subty = RELATED; asserteq!( multipart.tostring(), "multipart/related; boundary=dyEV84n7XNJ" );

const IMAGESVG: MediaType = MediaType::fromparts(IMAGE, SVG, Some(XML), None); let svg = MediaType::parse("IMAGE/SVG+XML").unwrap(); asserteq!(svg, IMAGESVG); ```

MediaTypeBuf

This is an owned and immutable version of MediaType.

```rust use mediatype::{names::, values::, MediaType, MediaTypeBuf};

let textplain: MediaTypeBuf = "text/plain; charset=UTF-8".parse().unwrap(); asserteq!(textplain.getparam(CHARSET).unwrap(), UTF_8);

let mut textplain: MediaType = textplain.toref(); textplain.subty = MARKDOWN; asserteq!(textplain.to_string(), "text/markdown; charset=UTF-8"); ```