Skip to content

Latest commit

History

History
67 lines (49 loc) 路 1.83 KB

README.md

File metadata and controls

67 lines (49 loc) 路 1.83 KB

headers-accept

馃 The missing `Accept` implementation for `headers::Header`

馃帹 Overview

This crate provides an implementation of headers::Header for Accept.

While other crates exist, they either rely on stagnant crates like mime (headers-accept uses mediatype instead) or deviate from RFC 9110 (by imposing onerous sort logic) or both.

This crate aims to solve these problems while adhereing to the spec outlined in section 12.5.1.

馃摝 Install

To use the crate in your project, add the following to your Cargo.toml file:

[dependencies]
headers-accept = "0.1.3"

馃じ Usage

Example

use std::str::FromStr;

use headers_accept::Accept;
use mediatype::MediaTypeBuf;

let accept = Accept::from_str("audio/*; q=0.2, audio/basic").unwrap();
let mut media_types = accept.media_types();
assert_eq!(
    media_types.next(),
    Some(&MediaTypeBuf::from_str("audio/basic").unwrap())
);
assert_eq!(
    media_types.next(),
    Some(&MediaTypeBuf::from_str("audio/*; q=0.2").unwrap())
);
assert_eq!(media_types.next(), None);

馃 Safety

This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% safe Rust.

馃懐 Contributing

We appreciate all kinds of contributions, thank you!