Crates.io | headers-accept |
lib.rs | headers-accept |
version | 0.1.4 |
source | src |
created_at | 2024-04-25 21:21:36.211141 |
updated_at | 2024-09-14 22:05:20.842823 |
description | 🤝 The missing `Accept` implementation for `headers::Header` |
homepage | https://github.com/maxcountryman/headers-accept |
repository | https://github.com/maxcountryman/headers-accept |
max_upload_size | |
id | 1220757 |
size | 32,005 |
🤝 The missing `Accept` implementation for `headers::Header`
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.
To use the crate in your project, add the following to your Cargo.toml
file:
[dependencies]
headers-accept = "0.1.4"
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);
This crate uses #![forbid(unsafe_code)]
to ensure everything is implemented in 100% safe Rust.
We appreciate all kinds of contributions, thank you!