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

project CI refresh #8

Merged
merged 17 commits into from
Apr 8, 2024
Merged
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
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2
updates:
- package-ecosystem: cargo
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 10
groups:
crates-io:
patterns:
- "*"
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: weekly
12 changes: 0 additions & 12 deletions .github/workflows/clippy-check.yml

This file was deleted.

100 changes: 52 additions & 48 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
on: [push, pull_request]

name: Continuous integration

on:
push:
pull_request:
merge_group:
schedule:
- cron: '0 18 * * *'

jobs:
check:
name: Check
Expand All @@ -10,80 +15,79 @@ jobs:
matrix:
rust:
- stable
- 1.44.0
- 1.63.0
chifflier marked this conversation as resolved.
Show resolved Hide resolved
- nightly
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- name: Install ${{ matrix.rust }} toolchain
uses: dtolnay/rust-toolchain@master
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- name: Cargo update
run: cargo update
- uses: actions-rs/cargo@v1
with:
command: check
- run: RUSTFLAGS="-D warnings" cargo check

test:
name: Test Suite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: test
- uses: actions/checkout@v4
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- run: cargo test
cpu marked this conversation as resolved.
Show resolved Hide resolved

fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
- uses: actions/checkout@v4
- name: Install stable rustfmt
uses: dtolnay/rust-toolchain@stable
with:
command: fmt
args: --all -- --check
components: rustfmt
- run: cargo fmt --all -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add clippy
- uses: actions-rs/cargo@v1
- uses: actions/checkout@v4
- name: Install nightly clippy
uses: dtolnay/rust-toolchain@nightly
with:
command: clippy
args: -- -D warnings
components: clippy
- run: cargo clippy -- -D warnings

doc:
name: Build documentation
runs-on: ubuntu-latest
env:
RUSTDOCFLAGS: --cfg docsrs
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
- uses: actions-rs/cargo@v1
- uses: actions/checkout@v4
- name: Install nightly rust
uses: dtolnay/rust-toolchain@nightly
- run: cargo doc --workspace --no-deps --all-features

semver:
name: Check semver compatibility
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Check semver
uses: obi1kenobi/cargo-semver-checks-action@v2

check-external-types:
name: Validate external types appearing in public API
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@master
with:
command: doc
args: --workspace --no-deps --all-features
toolchain: nightly-2024-02-07
# ^ sync with https://github.com/awslabs/cargo-check-external-types/blob/main/rust-toolchain.toml
chifflier marked this conversation as resolved.
Show resolved Hide resolved
- run: cargo install cargo-check-external-types
- run: cargo check-external-types
4 changes: 2 additions & 2 deletions .github/workflows/security-audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
security_audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions-rs/audit-check@v1
- uses: actions/checkout@v4
- uses: rustsec/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target
Cargo.lock
.*.swp
/.idea
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ homepage = "https://github.com/rusticata/rusticata-macros"
repository = "https://github.com/rusticata/rusticata-macros.git"
authors = ["Pierre Chifflier <chifflier@wzdftpd.net>"]
edition = "2018"
rust-version = "1.63"
categories = ["parsing"]
readme = "README.md"

Expand All @@ -24,4 +25,10 @@ std = ["nom/std"]
# document all features
all-features = true
# defines the configuration attribute `docsrs`
rustdoc-args = ["--cfg", "docsrs"]
rustdoc-args = ["--cfg", "docsrs"]

[package.metadata.cargo_check_external_types]
allowed_external_types = [
"nom",
"nom::*",
]
26 changes: 13 additions & 13 deletions src/combinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,32 +73,30 @@ where
}

/// Apply combinator, automatically converts between errors if the underlying type supports it
pub fn upgrade_error<I, O, E1: ParseError<I>, E2: ParseError<I>, F>(
mut f: F,
) -> impl FnMut(I) -> IResult<I, O, E2>
pub fn upgrade_error<I, O, E1, E2, F>(mut f: F) -> impl FnMut(I) -> IResult<I, O, E2>
where
E1: ParseError<I>,
E2: ParseError<I> + From<E1>,
F: FnMut(I) -> IResult<I, O, E1>,
E2: From<E1>,
{
move |i| f(i).map_err(nom::Err::convert)
}

/// Create a combinator that returns the provided value, and input unchanged
pub fn pure<I, O, E: ParseError<I>>(val: O) -> impl Fn(I) -> IResult<I, O, E>
pub fn pure<I, O, E>(val: O) -> impl Fn(I) -> IResult<I, O, E>
where
O: Clone,
E: ParseError<I>,
{
move |input: I| Ok((input, val.clone()))
}

/// Return a closure that takes `len` bytes from input, and applies `parser`.
pub fn flat_take<I, C, O, E: ParseError<I>, F>(
len: C,
mut parser: F,
) -> impl FnMut(I) -> IResult<I, O, E>
pub fn flat_take<I, C, O, E, F>(len: C, mut parser: F) -> impl FnMut(I) -> IResult<I, O, E>
where
I: InputTake + InputLength + InputIter,
C: ToUsize + Copy,
E: ParseError<I>,
F: Parser<I, O, E>,
{
// Note: this is the same as `map_parser(take(len), parser)`
Expand All @@ -110,23 +108,25 @@ where
}

/// Take `len` bytes from `input`, and apply `parser`.
pub fn flat_takec<I, O, E: ParseError<I>, C, F>(input: I, len: C, parser: F) -> IResult<I, O, E>
pub fn flat_takec<I, O, E, C, F>(input: I, len: C, parser: F) -> IResult<I, O, E>
where
C: ToUsize + Copy,
F: Parser<I, O, E>,
I: InputTake + InputLength + InputIter,
O: InputLength,
E: ParseError<I>,
C: ToUsize + Copy,
F: Parser<I, O, E>,
{
flat_take(len, parser)(input)
}

/// Helper macro for nom parsers: run first parser if condition is true, else second parser
pub fn cond_else<I, O, E: ParseError<I>, C, F, G>(
pub fn cond_else<I, O, E, C, F, G>(
cond: C,
mut first: F,
mut second: G,
) -> impl FnMut(I) -> IResult<I, O, E>
where
E: ParseError<I>,
C: Fn() -> bool,
F: Parser<I, O, E>,
G: Parser<I, O, E>,
Expand Down
2 changes: 1 addition & 1 deletion src/debug.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Helper functions and structures for debugging purpose

use alloc::{format, vec::Vec};
use alloc::format;
use core::fmt;
#[cfg(feature = "std")]
use nom::{
Expand Down
2 changes: 0 additions & 2 deletions src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Common traits

use alloc::vec::Vec;

/// Common trait for structures serialization
pub trait Serialize<O = Vec<u8>> {
/// Type of serialization error
Expand Down