diff --git a/.github/action-rs/grcov.yml b/.github/action-rs/grcov.yml new file mode 100644 index 0000000..d8ce523 --- /dev/null +++ b/.github/action-rs/grcov.yml @@ -0,0 +1,14 @@ +branch: true +ignore-not-existing: true +llvm: true +filter: covered +output-type: lcov +output-path: ./lcov.info +prefix-dir: /home/user/build/ +ignore: + - "/*" + - "C:/*" + - "../*" +path-mapping: + - "/path1" + - "/path2" diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..c741afb --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,65 @@ +name: Rust + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +env: + CARGO_TERM_COLOR: always + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + components: clippy, rustfmt + override: true + - uses: actions/checkout@v2 + - name: Check fmt + run: cargo fmt -- --check + - uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --all-features + - name: Build + run: cargo build + - name: Run tests + run: cargo test + + coverage: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + - name: Cargo clean + uses: actions-rs/cargo@v1 + with: + command: clean + - name: Cargo test + uses: actions-rs/cargo@v1 + with: + command: test + args: --all-features --no-fail-fast # Customize args for your own needs + env: + CARGO_INCREMENTAL: '0' + RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' + RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' + - name: Placeholder (run the example) + uses: actions-rs/cargo@v1 + with: + command: run + args: --example producer -- # needs a file there + - id: coverage + uses: actions-rs/grcov@v0.1 + - name: Coveralls upload + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: ${{ steps.coverage.outputs.report }} diff --git a/src/iter.rs b/src/iter.rs index 8633d7d..7b208e7 100755 --- a/src/iter.rs +++ b/src/iter.rs @@ -50,11 +50,10 @@ impl Iterator for PcapIterator { .fill_buf() .and_then(|b| { (if first_block { - parse_header(b) - .and_then(|(u, h)| Ok(Some((b.len() - u.len(), Block::Header(h))))) + parse_header(b).map(|(u, h)| Some((b.len() - u.len(), Block::Header(h)))) } else { parse_record(b, endianness, nano_sec) - .and_then(|(u, r)| Ok(Some((b.len() - u.len(), Block::Record(r))))) + .map(|(u, r)| Some((b.len() - u.len(), Block::Record(r)))) }) .or_else(|e| match e { Err::Incomplete(_) @@ -64,7 +63,7 @@ impl Iterator for PcapIterator { }) }) .unwrap_or(None) - .and_then(|(c, block)| { + .map(|(c, block)| { self.first_block = false; if c != 0 { self.reader.consume(c); @@ -73,7 +72,7 @@ impl Iterator for PcapIterator { self.endianness = h.endianness; self.nano_sec = h.nano_sec; } - Some(block) + block }) } } diff --git a/src/lib.rs b/src/lib.rs index 1e0f44f..0196580 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,6 +19,7 @@ use nom::{ /// Enumerates all frame format supported by pcap. #[allow(non_camel_case_types)] +#[allow(clippy::upper_case_acronyms)] #[derive(Debug, PartialEq, Copy, Clone)] pub enum LinkType { NULL, @@ -293,12 +294,12 @@ named_args!(parse_header_e(e: Endianness, nsec: bool)
, |val:&LinkType| { *val != LinkType::UNKNOWN } ) >> (Header { - major: major, - minor: minor, - this_zone: this_zone, - sigfigs: sigfigs, - snaplen: snaplen, - network: network, + major, + minor, + this_zone, + sigfigs, + snaplen, + network, nano_sec: nsec, endianness: e }) @@ -326,9 +327,9 @@ named_args!(pub parse_record(e: Endianness, nano_sec: bool), do_parse!( data: take!(incl_len) >> (Record { - ts_sec: ts_sec, + ts_sec, ts_nanosec: if nano_sec {ts_subsec} else {ts_subsec*1000}, - orig_len: orig_len, + orig_len, data: Vec::from(data) }) ));