Skip to content

Commit 8910121

Browse files
committed
Merge #34: Merge fork
f58baf7 chore: undo package rename (Jose Celano) 9833274 tests: add unit test for Value with serde_test (Jose Celano) f94c198 chore: add dev dependency serde_test (Jose Celano) 1eab404 test: add unit tests to Value (Jose Celano) b85b2a4 chore: add code coverage dir to gitignore (Jose Celano) 97168c5 chore: normalize todo mark to lowercase (Jose Celano) e2751eb chore(dev): add cargo alias (Jose Celano) fd7bdce test: add more tests for torrent files (Jose Celano) 9efb5e8 tests: enable tests with potencial unintended behavior (Jose Celano) a7fd343 test: add more failing tests (Jose Celano) a7587d4 docs: fix coverage workflow badge in README (Jose Celano) 252849f ci: add coverage workflow (Jose Celano) 5bc8202 ci: ignore failing tests (Jose Celano) 36e31ae docs: fix workflow badge link in README (Jose Celano) 885ebe9 chrore: update cSpell dictionary (Jose Celano) 5e9dd5c test: enable test (Jose Celano) 1ea262d ci: add benchmarking workflow (Jose Celano) b3b2a44 fix: [#9] Clipply errors (Jose Celano) cdd4200 fix: cargo build errors (Jose Celano) caf8cf5 doc: add new workflow badgets to README (Jose Celano) b3759c1 chore: bump actions/checkout from 3 to 4 (Jose Celano) 5b35fd7 ci: add cargo config (Jose Celano) a833a34 ci: add formatting and checking workflows (Jose Celano) e88aeec doc: add testing workflow badget to README (Jose Celano) 47549ef ci: add dependabot config (Jose Celano) 6ce2e9d test: add a failing test for nested list deserialization (Jose Celano) decdff6 Avoid eagerly allocating too much memory (5225225) a1597cc Add cargo-fuzz fuzzer (5225225) 43ba81e Introduce failing test for flattened enums (Nicholas Rempel) 625081a new torrust-serde-bencode package (Jose Celano) 403f043 Add test for ser/de of struct with vec of tuples (issue #17) (Adam Cigánek) 4faf05f Minor change to support rust version >= 1.40.0 (Adam Cigánek) 0c6c144 Fix deserialization of nested tuple (Adam Cigánek) 06bb9a6 Fix deserialization of flattened adjacently tagged enum (Adam Cigánek) 79b7540 Fix deserialization of adjacently tagged enums (Adam Cigánek) 1eecff4 Fix warnings and clippy lints (Adam Cigánek) e6f9b53 Apply rustfmt (Adam Cigánek) Pull request description: I have been working on a fork because this project was inactive, but I contacted @toby, who made me a maintainer and gave it access to publish new versions. I was trying to fix a bug I found [here](torrust/torrust-index#266). . After debugging, I realized the bug was already fixed in this repo but has yet to be included in a new release. I've been working on the fork and I would like to merge those changes back and publish the version `v0.2.4` on [crates.io](https://crates.io/crates/serde_bencode). The changes I've made so far are: - Fix cargo build and clippy warnings. - Merge PRs that were ready to merge. - Update dependencies. - Add GitHub workflows for checking, formatting, testing, benchmarking and coverage. - Add tests for torrent files, which I suppose is the most common use for this package. - Add unit tests for `Value` struct. ACKs for top commit: josecelano: ACK e894328 Tree-SHA512: 331e82dba9e0a8f4f2c9be30a09537707c39e05223d601bbfb7f6792a7e7e95b9bf60a65b097ed6ee2aea0e2c22196a8d6ded8c82cd9a59db274774002e50370
2 parents 09fede5 + e894328 commit 8910121

27 files changed

+1969
-328
lines changed

.cargo/config.toml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[alias]
2+
cov = "llvm-cov"
3+
cov-lcov = "llvm-cov --lcov --output-path=./.coverage/lcov.info"
4+
cov-html = "llvm-cov --html"
5+
time = "build --timings --all-targets"
6+
7+
[build]
8+
rustflags = [
9+
"-D",
10+
"warnings",
11+
"-D",
12+
"future-incompatible",
13+
"-D",
14+
"let-underscore",
15+
"-D",
16+
"nonstandard-style",
17+
"-D",
18+
"rust-2018-compatibility",
19+
"-D",
20+
"rust-2018-idioms",
21+
"-D",
22+
"rust-2021-compatibility",
23+
"-D",
24+
"unused",
25+
]

.github/dependabot.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: daily
7+
target-branch: "main"
8+
9+
- package-ecosystem: cargo
10+
directory: /
11+
schedule:
12+
interval: daily
13+
target-branch: "main"

.github/workflows/benchmarking.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Benchmarking
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
env:
8+
CARGO_TERM_COLOR: always
9+
10+
jobs:
11+
check:
12+
name: Benchmarking
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
toolchain: [nightly]
18+
19+
steps:
20+
- id: checkout
21+
name: Checkout Repository
22+
uses: actions/checkout@v4
23+
24+
- id: setup
25+
name: Setup Toolchain
26+
uses: dtolnay/rust-toolchain@stable
27+
with:
28+
toolchain: ${{ matrix.toolchain }}
29+
components: clippy
30+
31+
- id: cache
32+
name: Enable Workflow Cache
33+
uses: Swatinem/rust-cache@v2
34+
35+
- id: Benchmarking
36+
name: Run Benchmarking
37+
run: cargo bench

.github/workflows/checking.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Checking
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
env:
8+
CARGO_TERM_COLOR: always
9+
10+
jobs:
11+
check:
12+
name: Checking
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
toolchain: [stable, nightly]
18+
19+
steps:
20+
- id: checkout
21+
name: Checkout Repository
22+
uses: actions/checkout@v4
23+
24+
- id: setup
25+
name: Setup Toolchain
26+
uses: dtolnay/rust-toolchain@stable
27+
with:
28+
toolchain: ${{ matrix.toolchain }}
29+
components: clippy
30+
31+
- id: cache
32+
name: Enable Workflow Cache
33+
uses: Swatinem/rust-cache@v2
34+
35+
- id: check
36+
name: Run Build Checks
37+
run: cargo check --tests --examples --workspace --all-features
38+
39+
- id: lint
40+
name: Run Lint Checks
41+
run: cargo clippy --tests --examples --workspace --all-features -- -D clippy::correctness -D clippy::suspicious -D clippy::complexity -D clippy::perf -D clippy::style -D clippy::pedantic
42+
43+
- id: doc
44+
name: Run Documentation Checks
45+
run: cargo test --doc

.github/workflows/coverage.yaml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Coverage
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request_target:
8+
branches:
9+
- main
10+
11+
env:
12+
CARGO_TERM_COLOR: always
13+
14+
jobs:
15+
report:
16+
name: Report
17+
environment: coverage
18+
runs-on: ubuntu-latest
19+
env:
20+
CARGO_INCREMENTAL: "0"
21+
RUSTFLAGS: "-Z profile -C codegen-units=1 -C inline-threshold=0 -C link-dead-code -C overflow-checks=off -C panic=abort -Z panic_abort_tests"
22+
RUSTDOCFLAGS: "-Z profile -C codegen-units=1 -C inline-threshold=0 -C link-dead-code -C overflow-checks=off -C panic=abort -Z panic_abort_tests"
23+
24+
steps:
25+
- id: checkout_push
26+
if: github.event_name == 'push'
27+
name: Checkout Repository (Push)
28+
uses: actions/checkout@v4
29+
30+
- id: checkout_pull_request_target
31+
if: github.event_name == 'pull_request_target'
32+
name: Checkout Repository (Pull Request Target)
33+
uses: actions/checkout@v4
34+
with:
35+
ref: "refs/pull/${{ github.event.pull_request.number }}/head"
36+
37+
- id: setup
38+
name: Setup Toolchain
39+
uses: dtolnay/rust-toolchain@stable
40+
with:
41+
toolchain: nightly
42+
components: llvm-tools-preview
43+
44+
- id: cache
45+
name: Enable Workflow Cache
46+
uses: Swatinem/rust-cache@v2
47+
48+
- id: tools
49+
name: Install tools
50+
uses: taiki-e/install-action@v2
51+
with:
52+
tool: grcov,cargo-llvm-cov,nextest
53+
54+
- id: print
55+
name: Print Coverage Report
56+
run: cargo llvm-cov nextest
57+
58+
- id: report
59+
name: Generate Coverage Report
60+
uses: alekitto/[email protected]
61+
62+
- id: upload
63+
name: Upload Coverage Report
64+
uses: codecov/codecov-action@v3
65+
with:
66+
token: ${{ secrets.CODECOV_TOKEN }}
67+
files: ${{ steps.coverage.outputs.report }}
68+
verbose: true
69+
fail_ci_if_error: true

.github/workflows/formatting.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Formatting
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
env:
8+
CARGO_TERM_COLOR: always
9+
10+
jobs:
11+
format:
12+
name: Formatting
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- id: checkout
17+
name: Checkout Repository
18+
uses: actions/checkout@v4
19+
20+
- id: setup
21+
name: Setup Toolchain
22+
uses: dtolnay/rust-toolchain@stable
23+
with:
24+
toolchain: nightly
25+
components: rustfmt
26+
27+
- id: cache
28+
name: Enable Workflow Cache
29+
uses: Swatinem/rust-cache@v2
30+
31+
- id: format
32+
name: Run Formatting-Checks
33+
run: cargo fmt --check

.github/workflows/testing.yaml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Testing
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
env:
8+
CARGO_TERM_COLOR: always
9+
10+
jobs:
11+
test:
12+
name: Testing
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
toolchain: [stable, nightly]
18+
19+
steps:
20+
- id: checkout
21+
name: Checkout Repository
22+
uses: actions/checkout@v4
23+
24+
- id: setup
25+
name: Setup Toolchain
26+
uses: dtolnay/rust-toolchain@stable
27+
with:
28+
toolchain: ${{ matrix.toolchain }}
29+
components: llvm-tools-preview
30+
31+
- id: cache
32+
name: Enable Job Cache
33+
uses: Swatinem/rust-cache@v2
34+
35+
- id: test
36+
name: Run Unit Tests
37+
run: cargo test --tests --examples --workspace --all-features

.gitignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
target
2-
Cargo.lock
1+
.coverage
32
*.rustfmt
3+
Cargo.lock
4+
target
5+

.vscode/extensions.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"streetsidesoftware.code-spell-checker",
4+
"rust-lang.rust-analyzer"
5+
]
6+
}

.vscode/settings.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"[rust]": {
3+
"editor.formatOnSave": true
4+
},
5+
"rust-analyzer.checkOnSave": true,
6+
"rust-analyzer.check.command": "clippy",
7+
"rust-analyzer.check.allTargets": true,
8+
"rust-analyzer.check.extraArgs": [
9+
"--",
10+
"-D",
11+
"clippy::correctness",
12+
"-D",
13+
"clippy::suspicious",
14+
"-W",
15+
"clippy::complexity",
16+
"-W",
17+
"clippy::perf",
18+
"-W",
19+
"clippy::style",
20+
"-W",
21+
"clippy::pedantic",
22+
],
23+
"rust-analyzer.linkedProjects": [
24+
"./Cargo.toml"
25+
],
26+
}

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "serde_bencode"
33
description = "A Serde backed Bencode encoding/decoding library for Rust."
44
version = "0.2.3"
5-
authors = ["Toby Padilla <[email protected]>"]
5+
authors = ["Toby Padilla <[email protected]>", "Nautilus Cyberneering <[email protected]>"]
66
repository = "https://github.com/toby/serde-bencode"
77
documentation = "https://docs.rs/serde_bencode/"
88
license = "MIT"
@@ -15,3 +15,4 @@ serde_bytes = "0.11"
1515

1616
[dev-dependencies]
1717
serde_derive = "1.0"
18+
serde_test = "1.0.176"

README.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# serde-bencode
1+
# Torrust Serde Bencode
2+
3+
[![Checking](https://github.com/torrust/torrust-serde-bencode/actions/workflows/checking.yml/badge.svg)](https://github.com/torrust/torrust-serde-bencode/actions/workflows/checking.yml) [![Formatting](https://github.com/torrust/torrust-serde-bencode/actions/workflows/formatting.yml/badge.svg)](https://github.com/torrust/torrust-serde-bencode/actions/workflows/formatting.yml) [![Testing](https://github.com/torrust/torrust-serde-bencode/actions/workflows/testing.yaml/badge.svg)](https://github.com/torrust/torrust-serde-bencode/actions/workflows/testing.yaml) [![Benchmarking](https://github.com/torrust/torrust-serde-bencode/actions/workflows/benchmarking.yml/badge.svg)](https://github.com/torrust/torrust-serde-bencode/actions/workflows/benchmarking.yml) [![Coverage](https://github.com/torrust/torrust-serde-bencode/actions/workflows/coverage.yaml/badge.svg)](https://github.com/torrust/torrust-serde-bencode/actions/workflows/coverage.yaml) [![Crates.io](https://img.shields.io/crates/v/serde_bencode)](https://crates.io/crates/serde_bencode) [![docs.rs](https://img.shields.io/docsrs/serde_bencode)](https://docs.rs/serde_bencode)
24

35
**Archived:** I no longer maintain this repo as I've moved to [Go full-time](https://charm.sh). Please see [torrust/torrust-serde-bencode](https://github.com/torrust/torrust-serde-bencode) for a maintained fork.
46

@@ -11,13 +13,17 @@ Add the following to your `Cargo.toml`:
1113

1214
```toml
1315
[dependencies]
14-
serde_bencode = "^0.2.3"
16+
torrust-serde-bencode = "^0.2.3"
1517
serde = "^1.0.0"
1618
serde_derive = "^1.0.0"
1719
```
1820

1921
## Usage
2022

21-
This is an abbreviated `.torrent` parsing example from
22-
[examples/parse_torrent.rs](examples/parse_torrent.rs). If you compile this crate as a binary, it
23-
will print metadata for any Torrent sent to stdin.
23+
This is an abbreviated `.torrent` parsing example from [examples/parse_torrent.rs](examples/parse_torrent.rs). If you compile this crate as a binary, it will print metadata for any Torrent sent to stdin.
24+
25+
## Benchmarking
26+
27+
```console
28+
cargo bench
29+
```

benches/benches.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
#![feature(test)]
22

33
extern crate test;
4-
extern crate serde;
54
#[macro_use]
65
extern crate serde_derive;
7-
extern crate serde_bencode;
86

9-
use test::Bencher;
107
use serde::Serialize;
11-
use serde_bencode::ser::Serializer;
128
use serde_bencode::de::from_bytes;
13-
9+
use serde_bencode::ser::Serializer;
10+
use test::Bencher;
1411

1512
#[bench]
1613
fn ser_de_simple(b: &mut Bencher) {
@@ -21,7 +18,7 @@ fn ser_de_simple(b: &mut Bencher) {
2118
}
2219

2320
b.iter(|| {
24-
let a = Fake {a: 2, b: 7};
21+
let a = Fake { a: 2, b: 7 };
2522
let mut ser = Serializer::new();
2623
a.serialize(&mut ser).unwrap();
2724
let b: Fake = from_bytes(ser.as_ref()).unwrap();
@@ -44,7 +41,10 @@ fn ser_de_nested(b: &mut Bencher) {
4441
}
4542

4643
b.iter(|| {
47-
let a = FakeB {a: 2, b: FakeA {a: 7, b: 9}};
44+
let a = FakeB {
45+
a: 2,
46+
b: FakeA { a: 7, b: 9 },
47+
};
4848
let mut ser = Serializer::new();
4949
a.serialize(&mut ser).unwrap();
5050
let b: FakeB = from_bytes(ser.as_ref()).unwrap();

0 commit comments

Comments
 (0)