Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcountryman committed Apr 25, 2024
0 parents commit 7842070
Show file tree
Hide file tree
Showing 9 changed files with 520 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2

updates:
- package-ecosystem: "cargo"
directory: "/"
schedule:
interval: "daily"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
63 changes: 63 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Rust

on:
push:
branches:
- main
pull_request: {}

env:
CARGO_TERM_COLOR: always

jobs:
check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- run: |
rustup toolchain install nightly --profile minimal --component rustfmt --component clippy
- uses: Swatinem/rust-cache@v2
- name: clippy
run: |
cargo clippy --all --all-targets --all-features -- -Dwarnings
- name: rustfmt
run: |
cargo +nightly fmt --all -- --check
check-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
rustup toolchain install stable --profile minimal
- uses: Swatinem/rust-cache@v2
- name: cargo doc
env:
RUSTDOCFLAGS: "-D rustdoc::broken-intra-doc-links"
run: |
cargo doc --all-features --no-deps
test-docs:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
rustup toolchain install nightly --profile minimal
- uses: Swatinem/rust-cache@v2
- name: Run doc tests
run: |
cargo test --all-features --doc
test-unit:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
rustup toolchain install stable --profile minimal
- uses: Swatinem/rust-cache@v2
- name: Run unit tests
run: |
cargo test --lib --all-features
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
56 changes: 56 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "headers-accept"
version = "0.1.0"
edition = "2021"
authors = ["Max Countryman <hello@maxcountryman.com>"]
categories = ["network-programming", "web-programming"]
description = "🤝 The missing `Accept` implementation for `headers::Header`"
homepage = "https://github.com/maxcountryman/headers-accept"
keywords = ["http", "headers", "accept", "headers-accept"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/maxcountryman/headers-accept"

[dependencies]
headers-core = "0.3.0"
http = "1.1.0"
mediatype = "0.19.18"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Max Countryman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<h1 align="center">
headers-accept
</h1>

<p align="center">
🤝 The missing `Accept` implementation for `headers::Header`
</p>

<div align="center">
<a href="https://crates.io/crates/headers-accept">
<img src="https://img.shields.io/crates/v/headers-accept.svg" />
</a>
<a href="https://docs.rs/headers-accept">
<img src="https://docs.rs/headers-accept/badge.svg" />
</a>
<a href="https://github.com/maxcountryman/headers-accept/actions/workflows/rust.yml">
<img src="https://github.com/maxcountryman/headers-accept/actions/workflows/rust.yml/badge.svg" />
</a>
</div>

## 🎨 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 7231 (by imposing onerous sort logic) or both.

This crate aims to solve these problems while adhereing to the spec outlined in [section 5.3.2](https://www.rfc-editor.org/rfc/rfc7231#section-5.3.2).

## 📦 Install

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

```toml
[dependencies]
headers-accept = "0.1.0"
```

## 🤸 Usage

### Example

```rust
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!
5 changes: 5 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
format_code_in_doc_comments = true
format_strings = true
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
wrap_comments = true
Loading

0 comments on commit 7842070

Please sign in to comment.