Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Commit 625081a

Browse files
committed
new torrust-serde-bencode package
Minor changes and package configuration changed.
1 parent 553adb4 commit 625081a

File tree

10 files changed

+117
-34
lines changed

10 files changed

+117
-34
lines changed

.github/workflows/testing.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Testing
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
env:
8+
CARGO_TERM_COLOR: always
9+
10+
jobs:
11+
unit:
12+
name: Units
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@v3
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 --benches --examples --workspace --all-targets --all-features
38+

.vscode/extensions.json

Lines changed: 6 additions & 0 deletions
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

Lines changed: 26 additions & 0 deletions
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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[package]
2-
name = "serde_bencode"
2+
name = "torrust-serde-bencode"
33
description = "A Serde backed Bencode encoding/decoding library for Rust."
44
version = "0.2.3"
5-
authors = ["Toby Padilla <tobypadilla@gmail.com>"]
6-
repository = "https://github.com/toby/serde-bencode"
7-
documentation = "https://docs.rs/serde_bencode/"
5+
authors = ["Toby Padilla <tobypadilla@gmail.com>", "Nautilus Cyberneering <info@nautilus-cyberneering.de>"]
6+
repository = "https://github.com/torrust/torrust-serde-bencode"
7+
documentation = "https://docs.rs/torrust-serde-bencode/"
88
license = "MIT"
99
keywords = ["bencode", "serialize", "deserialize", "serde"]
1010
edition = "2018"

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
# serde-bencode
1+
# Torrust Serde Bencode
22

33
A [Serde](https://github.com/serde-rs/serde) backed [Bencode](https://en.wikipedia.org/wiki/Bencode)
44
encoding/decoding library for Rust.
55

6+
Forked from: <https://github.com/toby/serde-bencode> due to inactivity in upstream repo.
7+
68
## Installation
79

810
Add the following to your `Cargo.toml`:
911

1012
```toml
1113
[dependencies]
12-
serde_bencode = "^0.2.3"
14+
torrust-serde-bencode = "^0.2.3"
1315
serde = "^1.0.0"
1416
serde_derive = "^1.0.0"
1517
```
1618

1719
## Usage
1820

19-
This is an abbreviated `.torrent` parsing example from
20-
[examples/parse_torrent.rs](examples/parse_torrent.rs). If you compile this crate as a binary, it
21-
will print metadata for any Torrent sent to stdin.
21+
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.

benches/benches.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
#![feature(test)]
22

3-
extern crate test;
43
extern crate serde;
4+
extern crate test;
55
#[macro_use]
66
extern crate serde_derive;
7-
extern crate serde_bencode;
7+
extern crate torrust_serde_bencode;
88

9-
use test::Bencher;
109
use serde::Serialize;
11-
use serde_bencode::ser::Serializer;
12-
use serde_bencode::de::from_bytes;
13-
10+
use test::Bencher;
11+
use torrust_serde_bencode::de::from_bytes;
12+
use torrust_serde_bencode::ser::Serializer;
1413

1514
#[bench]
1615
fn ser_de_simple(b: &mut Bencher) {
@@ -21,7 +20,7 @@ fn ser_de_simple(b: &mut Bencher) {
2120
}
2221

2322
b.iter(|| {
24-
let a = Fake {a: 2, b: 7};
23+
let a = Fake { a: 2, b: 7 };
2524
let mut ser = Serializer::new();
2625
a.serialize(&mut ser).unwrap();
2726
let b: Fake = from_bytes(ser.as_ref()).unwrap();
@@ -44,7 +43,10 @@ fn ser_de_nested(b: &mut Bencher) {
4443
}
4544

4645
b.iter(|| {
47-
let a = FakeB {a: 2, b: FakeA {a: 7, b: 9}};
46+
let a = FakeB {
47+
a: 2,
48+
b: FakeA { a: 7, b: 9 },
49+
};
4850
let mut ser = Serializer::new();
4951
a.serialize(&mut ser).unwrap();
5052
let b: FakeB = from_bytes(ser.as_ref()).unwrap();

cSpell.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"words": [
3+
"bencoded",
4+
"Serde"
5+
],
6+
"enableFiletypes": [
7+
"dockerfile",
8+
"shellscript",
9+
"toml"
10+
]
11+
}

examples/parse_torrent.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
extern crate serde;
2-
extern crate serde_bencode;
2+
extern crate torrust_serde_bencode;
33
#[macro_use]
44
extern crate serde_derive;
55
extern crate serde_bytes;
66

7-
use serde_bencode::de;
87
use serde_bytes::ByteBuf;
98
use std::io::{self, Read};
9+
use torrust_serde_bencode::de;
1010

1111
#[derive(Debug, Deserialize)]
1212
struct Node(String, i64);
@@ -21,23 +21,23 @@ struct File {
2121

2222
#[derive(Debug, Deserialize)]
2323
struct Info {
24-
name: String,
25-
pieces: ByteBuf,
24+
pub name: String,
25+
pub pieces: ByteBuf,
2626
#[serde(rename = "piece length")]
27-
piece_length: i64,
27+
pub piece_length: i64,
2828
#[serde(default)]
29-
md5sum: Option<String>,
29+
pub md5sum: Option<String>,
3030
#[serde(default)]
31-
length: Option<i64>,
31+
pub length: Option<i64>,
3232
#[serde(default)]
33-
files: Option<Vec<File>>,
33+
pub files: Option<Vec<File>>,
3434
#[serde(default)]
35-
private: Option<u8>,
35+
pub private: Option<u8>,
3636
#[serde(default)]
37-
path: Option<Vec<String>>,
37+
pub path: Option<Vec<String>>,
3838
#[serde(default)]
3939
#[serde(rename = "root hash")]
40-
root_hash: Option<String>,
40+
pub root_hash: Option<String>,
4141
}
4242

4343
#[derive(Debug, Deserialize)]

src/de.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::io::Read;
99
use std::str;
1010

1111
#[doc(hidden)]
12-
// TODO: This should be pub(crate).
12+
// todo: This should be pub(crate).
1313
pub struct BencodeAccess<'a, R: 'a + Read> {
1414
de: &'a mut Deserializer<R>,
1515
len: Option<usize>,

tests/tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
extern crate serde_bencode;
1+
extern crate torrust_serde_bencode;
22

33
use serde::de::DeserializeOwned;
44
use serde::Serialize;
5-
use serde_bencode::de::{from_bytes, from_str};
6-
use serde_bencode::error::Result;
7-
use serde_bencode::ser::{to_bytes, to_string, Serializer};
8-
use serde_bencode::value::Value;
95
use serde_derive::{Deserialize, Serialize};
106
use std::collections::HashMap;
117
use std::fmt::Debug;
8+
use torrust_serde_bencode::de::{from_bytes, from_str};
9+
use torrust_serde_bencode::error::Result;
10+
use torrust_serde_bencode::ser::{to_bytes, to_string, Serializer};
11+
use torrust_serde_bencode::value::Value;
1212

1313
fn test_value_ser_de<T: Into<Value>>(a: T) {
1414
let a = a.into();

0 commit comments

Comments
 (0)