Skip to content

Commit

Permalink
Merge #34: Merge fork
Browse files Browse the repository at this point in the history
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
  • Loading branch information
josecelano committed Oct 9, 2023
2 parents 09fede5 + e894328 commit 8910121
Show file tree
Hide file tree
Showing 27 changed files with 1,969 additions and 328 deletions.
25 changes: 25 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[alias]
cov = "llvm-cov"
cov-lcov = "llvm-cov --lcov --output-path=./.coverage/lcov.info"
cov-html = "llvm-cov --html"
time = "build --timings --all-targets"

[build]
rustflags = [
"-D",
"warnings",
"-D",
"future-incompatible",
"-D",
"let-underscore",
"-D",
"nonstandard-style",
"-D",
"rust-2018-compatibility",
"-D",
"rust-2018-idioms",
"-D",
"rust-2021-compatibility",
"-D",
"unused",
]
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
target-branch: "main"

- package-ecosystem: cargo
directory: /
schedule:
interval: daily
target-branch: "main"
37 changes: 37 additions & 0 deletions .github/workflows/benchmarking.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Benchmarking

on:
push:
pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
check:
name: Benchmarking
runs-on: ubuntu-latest

strategy:
matrix:
toolchain: [nightly]

steps:
- id: checkout
name: Checkout Repository
uses: actions/checkout@v4

- id: setup
name: Setup Toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.toolchain }}
components: clippy

- id: cache
name: Enable Workflow Cache
uses: Swatinem/rust-cache@v2

- id: Benchmarking
name: Run Benchmarking
run: cargo bench
45 changes: 45 additions & 0 deletions .github/workflows/checking.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Checking

on:
push:
pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
check:
name: Checking
runs-on: ubuntu-latest

strategy:
matrix:
toolchain: [stable, nightly]

steps:
- id: checkout
name: Checkout Repository
uses: actions/checkout@v4

- id: setup
name: Setup Toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.toolchain }}
components: clippy

- id: cache
name: Enable Workflow Cache
uses: Swatinem/rust-cache@v2

- id: check
name: Run Build Checks
run: cargo check --tests --examples --workspace --all-features

- id: lint
name: Run Lint Checks
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

- id: doc
name: Run Documentation Checks
run: cargo test --doc
69 changes: 69 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Coverage

on:
push:
branches:
- main
pull_request_target:
branches:
- main

env:
CARGO_TERM_COLOR: always

jobs:
report:
name: Report
environment: coverage
runs-on: ubuntu-latest
env:
CARGO_INCREMENTAL: "0"
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"
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"

steps:
- id: checkout_push
if: github.event_name == 'push'
name: Checkout Repository (Push)
uses: actions/checkout@v4

- id: checkout_pull_request_target
if: github.event_name == 'pull_request_target'
name: Checkout Repository (Pull Request Target)
uses: actions/checkout@v4
with:
ref: "refs/pull/${{ github.event.pull_request.number }}/head"

- id: setup
name: Setup Toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
components: llvm-tools-preview

- id: cache
name: Enable Workflow Cache
uses: Swatinem/rust-cache@v2

- id: tools
name: Install tools
uses: taiki-e/install-action@v2
with:
tool: grcov,cargo-llvm-cov,nextest

- id: print
name: Print Coverage Report
run: cargo llvm-cov nextest

- id: report
name: Generate Coverage Report
uses: alekitto/grcov@v0.2

- id: upload
name: Upload Coverage Report
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ${{ steps.coverage.outputs.report }}
verbose: true
fail_ci_if_error: true
33 changes: 33 additions & 0 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Formatting

on:
push:
pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
format:
name: Formatting
runs-on: ubuntu-latest

steps:
- id: checkout
name: Checkout Repository
uses: actions/checkout@v4

- id: setup
name: Setup Toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
components: rustfmt

- id: cache
name: Enable Workflow Cache
uses: Swatinem/rust-cache@v2

- id: format
name: Run Formatting-Checks
run: cargo fmt --check
37 changes: 37 additions & 0 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Testing

on:
push:
pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
test:
name: Testing
runs-on: ubuntu-latest

strategy:
matrix:
toolchain: [stable, nightly]

steps:
- id: checkout
name: Checkout Repository
uses: actions/checkout@v4

- id: setup
name: Setup Toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.toolchain }}
components: llvm-tools-preview

- id: cache
name: Enable Job Cache
uses: Swatinem/rust-cache@v2

- id: test
name: Run Unit Tests
run: cargo test --tests --examples --workspace --all-features
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
target
Cargo.lock
.coverage
*.rustfmt
Cargo.lock
target

6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"streetsidesoftware.code-spell-checker",
"rust-lang.rust-analyzer"
]
}
26 changes: 26 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"[rust]": {
"editor.formatOnSave": true
},
"rust-analyzer.checkOnSave": true,
"rust-analyzer.check.command": "clippy",
"rust-analyzer.check.allTargets": true,
"rust-analyzer.check.extraArgs": [
"--",
"-D",
"clippy::correctness",
"-D",
"clippy::suspicious",
"-W",
"clippy::complexity",
"-W",
"clippy::perf",
"-W",
"clippy::style",
"-W",
"clippy::pedantic",
],
"rust-analyzer.linkedProjects": [
"./Cargo.toml"
],
}
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "serde_bencode"
description = "A Serde backed Bencode encoding/decoding library for Rust."
version = "0.2.3"
authors = ["Toby Padilla <tobypadilla@gmail.com>"]
authors = ["Toby Padilla <tobypadilla@gmail.com>", "Nautilus Cyberneering <info@nautilus-cyberneering.de>"]
repository = "https://github.com/toby/serde-bencode"
documentation = "https://docs.rs/serde_bencode/"
license = "MIT"
Expand All @@ -15,3 +15,4 @@ serde_bytes = "0.11"

[dev-dependencies]
serde_derive = "1.0"
serde_test = "1.0.176"
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# serde-bencode
# Torrust Serde Bencode

[![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)

**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.

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

```toml
[dependencies]
serde_bencode = "^0.2.3"
torrust-serde-bencode = "^0.2.3"
serde = "^1.0.0"
serde_derive = "^1.0.0"
```

## Usage

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.
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.

## Benchmarking

```console
cargo bench
```
14 changes: 7 additions & 7 deletions benches/benches.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#![feature(test)]

extern crate test;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_bencode;

use test::Bencher;
use serde::Serialize;
use serde_bencode::ser::Serializer;
use serde_bencode::de::from_bytes;

use serde_bencode::ser::Serializer;
use test::Bencher;

#[bench]
fn ser_de_simple(b: &mut Bencher) {
Expand All @@ -21,7 +18,7 @@ fn ser_de_simple(b: &mut Bencher) {
}

b.iter(|| {
let a = Fake {a: 2, b: 7};
let a = Fake { a: 2, b: 7 };
let mut ser = Serializer::new();
a.serialize(&mut ser).unwrap();
let b: Fake = from_bytes(ser.as_ref()).unwrap();
Expand All @@ -44,7 +41,10 @@ fn ser_de_nested(b: &mut Bencher) {
}

b.iter(|| {
let a = FakeB {a: 2, b: FakeA {a: 7, b: 9}};
let a = FakeB {
a: 2,
b: FakeA { a: 7, b: 9 },
};
let mut ser = Serializer::new();
a.serialize(&mut ser).unwrap();
let b: FakeB = from_bytes(ser.as_ref()).unwrap();
Expand Down
Loading

0 comments on commit 8910121

Please sign in to comment.