Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub CI and fix all found issues #163

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: CI
on:
pull_request:
branches: [ main ]
push:
branches: [ main ]

# Concurrency strategy:
# github.workflow: distinguish this workflow from others
# github.event_name: distinguish `push` event from `pull_request` event
# github.event.number: set to the number of the pull request if `pull_request` event
# github.run_id: otherwise, it's a `push` event, only cancel if we rerun the workflow
#
# Reference:
# https://docs.github.com/en/actions/using-jobs/using-concurrency
# https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.number || github.run_id }}
cancel-in-progress: true
jobs:
check:
name: Check
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Install toolchain
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt,clippy
- uses: Swatinem/rust-cache@v2
- name: Check format
run: cargo +nightly fmt --all
- name: Check clippy
run: cargo +nightly clippy --all-targets --all-features -- -D warnings

test:
name: Run tests
strategy:
matrix:
rust-version: [ stable, beta, nightly ]
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: Install toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust-version }}
- name: Build all targets
run: cargo build --workspace --all-features --bins --tests --examples --benches --lib
- name: Run unit tests
shell: bash
run: cargo test --all-features -- --nocapture

required:
name: Required
runs-on: ubuntu-22.04
if: ${{ always() }}
needs:
- check
- test
steps:
- name: Guardian
run: |
if [[ ! ( \
"${{ needs.check.result }}" == "success" \
&& "${{ needs.test.result }}" == "success" \
) ]]; then
echo "Required jobs haven't been completed successfully."
exit -1
fi
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

6 changes: 0 additions & 6 deletions CONTRIBUTING.md

This file was deleted.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[package]

name = "mime"
version = "0.4.0-a.0" # remember to update html_root_url
authors = ["Sean McArthur <[email protected]>"]
Expand All @@ -17,15 +16,15 @@ mime-macro = { path = "./mime-macro", optional = true }
mime-parse = { path = "./mime-parse" }
proc-macro-hack = { version = "0.5", optional = true }
quoted-string = "0.2.2"
serde1 = { version = "1", optional = true, package = "serde" }
serde1 = { version = "1.0", optional = true, package = "serde" }

[features]
macro = ["mime-macro", "proc-macro-hack"]
# "serde1" optional support

[workspace]
members = [
"./",
".",
"mime-macro",
"mime-parse",
]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014-2019 Sean McArthur
Copyright (c) 2014-2024 Sean McArthur

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
# mime

[![Build Status](https://travis-ci.org/hyperium/mime.svg?branch=master)](https://travis-ci.org/hyperium/mime)
[![crates.io](https://img.shields.io/crates/v/mime.svg)](https://crates.io/crates/mime)
[![docs.rs](https://docs.rs/mime/badge.svg)](https://docs.rs/mime)

Support MIME (HTTP Media Types) as strong types in Rust.

[Documentation](https://docs.rs/mime)

## Usage

```rust
extern crate mime;

fn main() {
// common types are constants
let text = mime::TEXT_PLAIN;
Expand All @@ -21,13 +16,21 @@ fn main() {
match (text.type_(), text.subtype()) {
(mime::TEXT, mime::PLAIN) => {
// plain text!
},
}
(mime::TEXT, _) => {
// structured text!
},
}
_ => {
// not text!
}
}
}
```

## Documentation

Read the online documents at https://docs.rs/mime.

## License

This project is licensed under [The MIT License](LICENSE).
10 changes: 6 additions & 4 deletions benches/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn bench_eq_parsed_atom(b: &mut Bencher) {
#[bench]
fn bench_eq_parsed_dynamic(b: &mut Bencher) {
let mime1 = "text/foo; charset=utf-8".parse::<MediaType>().unwrap();
let mime2 = mime1.clone();
let mime2 = mime1.clone();
b.bytes = mime1.as_ref().len() as u64;
b.iter(|| {
assert_eq!(mime1, mime2);
Expand All @@ -27,8 +27,10 @@ fn bench_eq_parsed_dynamic(b: &mut Bencher) {

#[bench]
fn bench_eq_multiple_parameters(b: &mut Bencher) {
let mime1 = "text/foo; aaa=bbb; ccc=ddd; eee=fff; ggg=hhh".parse::<MediaType>().unwrap();
let mime2 = mime1.clone();
let mime1 = "text/foo; aaa=bbb; ccc=ddd; eee=fff; ggg=hhh"
.parse::<MediaType>()
.unwrap();
let mime2 = mime1.clone();
b.bytes = mime1.as_ref().len() as u64;
b.iter(|| {
assert_eq!(mime1, mime2);
Expand Down Expand Up @@ -65,7 +67,7 @@ fn bench_ne_consts(b: &mut Bencher) {
}

#[bench]
fn bench_eq_type_(b: &mut Bencher) {
fn bench_eq_type(b: &mut Bencher) {
let mime = TEXT_PLAIN_UTF_8;
let name = TEXT;
b.bytes = name.len() as u64;
Expand Down
8 changes: 5 additions & 3 deletions benches/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ use test::Bencher;
#[bench]
fn bench_fmt(b: &mut Bencher) {
use std::fmt::Write;
let mime = ::mime::TEXT_PLAIN_UTF_8;
let mime = mime::TEXT_PLAIN_UTF_8;
b.bytes = mime.to_string().as_bytes().len() as u64;
let mut s = String::with_capacity(64);
b.iter(|| {
let _ = write!(s, "{}", mime);
::test::black_box(&s);
unsafe { s.as_mut_vec().set_len(0); }
test::black_box(&s);
unsafe {
s.as_mut_vec().set_len(0);
}
})
}
1 change: 0 additions & 1 deletion benches/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ extern crate test;
use mime::MediaType;
use test::Bencher;


#[bench]
fn text_plain(b: &mut Bencher) {
let s = "text/plain";
Expand Down
7 changes: 3 additions & 4 deletions mime-macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[package]

name = "mime-macro"
version = "0.0.0"
description = "mime procedural macros"
Expand All @@ -14,7 +13,7 @@ proc-macro = true

[dependencies]
mime-parse = { path = "../mime-parse" }
proc-macro2 = "0.4"
proc-macro2 = "1.0"
proc-macro-hack = "0.5"
quote = "0.6"
syn = "0.15"
quote = "1.0"
syn = "2.0"
17 changes: 6 additions & 11 deletions mime-macro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
extern crate proc_macro;

use proc_macro::TokenStream;
use proc_macro_hack::proc_macro_hack;
use proc_macro2::Span;
use proc_macro_hack::proc_macro_hack;
use quote::quote;

#[proc_macro_hack]
Expand All @@ -24,13 +22,13 @@ pub fn media_type(tokens: TokenStream) -> TokenStream {
quote! {
$crate::private::Source::Atom(0, #s)
}
},
}
a => {
let s = mime.as_ref();
quote! {
$crate::private::Source::Atom(#a, #s)
}
},
}
};
let slash = mime.private_subtype_offset();
let plus = match mime.private_suffix_offset() {
Expand Down Expand Up @@ -66,13 +64,10 @@ fn parse_mime_lit(value: &str) -> Result<mime_parse::Mime, String> {

match mime {
Ok(mime) => match mime.private_params_source() {
mime_parse::ParamSource::None |
mime_parse::ParamSource::Utf8(_) => Ok(mime),
mime_parse::ParamSource::None | mime_parse::ParamSource::Utf8(_) => Ok(mime),
mime_parse::ParamSource::One(..) => Ok(mime),
_ => Err("multiple parameters not supported yet".into())
_ => Err("multiple parameters not supported yet".into()),
},
Err(err) => {
Err(format!("invalid MediaType: {}", err))
}
Err(err) => Err(format!("invalid MediaType: {}", err)),
}
}
1 change: 0 additions & 1 deletion mime-parse/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[package]

name = "mime-parse"
version = "0.0.0"
description = "mime parsing internals"
Expand Down
Loading