diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml new file mode 100644 index 0000000..d4e1d28 --- /dev/null +++ b/.github/workflows/testing.yaml @@ -0,0 +1,38 @@ +name: Testing + +on: + push: + pull_request: + +env: + CARGO_TERM_COLOR: always + +jobs: + unit: + name: Units + runs-on: ubuntu-latest + + strategy: + matrix: + toolchain: [stable, nightly] + + steps: + - id: checkout + name: Checkout Repository + uses: actions/checkout@v3 + + - 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 --benches --examples --workspace --all-targets --all-features + \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..56f54e5 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "streetsidesoftware.code-spell-checker", + "rust-lang.rust-analyzer" + ] + } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..1347a59 --- /dev/null +++ b/.vscode/settings.json @@ -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" + ], + } \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 7b212ad..f8bcb46 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [package] -name = "serde_bencode" +name = "torrust-serde-bencode" description = "A Serde backed Bencode encoding/decoding library for Rust." version = "0.2.3" -authors = ["Toby Padilla "] -repository = "https://github.com/toby/serde-bencode" -documentation = "https://docs.rs/serde_bencode/" +authors = ["Toby Padilla ", "Nautilus Cyberneering "] +repository = "https://github.com/torrust/torrust-serde-bencode" +documentation = "https://docs.rs/torrust-serde-bencode/" license = "MIT" keywords = ["bencode", "serialize", "deserialize", "serde"] edition = "2018" diff --git a/README.md b/README.md index 66acff4..2ec7045 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,21 @@ -# serde-bencode +# Torrust Serde Bencode A [Serde](https://github.com/serde-rs/serde) backed [Bencode](https://en.wikipedia.org/wiki/Bencode) encoding/decoding library for Rust. +Forked from: due to inactivity in upstream repo. + ## Installation 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. diff --git a/benches/benches.rs b/benches/benches.rs index f5432e1..c99384c 100644 --- a/benches/benches.rs +++ b/benches/benches.rs @@ -1,16 +1,15 @@ #![feature(test)] -extern crate test; extern crate serde; +extern crate test; #[macro_use] extern crate serde_derive; -extern crate serde_bencode; +extern crate torrust_serde_bencode; -use test::Bencher; use serde::Serialize; -use serde_bencode::ser::Serializer; -use serde_bencode::de::from_bytes; - +use test::Bencher; +use torrust_serde_bencode::de::from_bytes; +use torrust_serde_bencode::ser::Serializer; #[bench] fn ser_de_simple(b: &mut Bencher) { @@ -21,7 +20,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(); @@ -44,7 +43,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(); diff --git a/cSpell.json b/cSpell.json new file mode 100644 index 0000000..299e9bb --- /dev/null +++ b/cSpell.json @@ -0,0 +1,11 @@ +{ + "words": [ + "bencoded", + "Serde" + ], + "enableFiletypes": [ + "dockerfile", + "shellscript", + "toml" + ] +} diff --git a/examples/parse_torrent.rs b/examples/parse_torrent.rs index c92a67a..ae60862 100644 --- a/examples/parse_torrent.rs +++ b/examples/parse_torrent.rs @@ -1,12 +1,12 @@ extern crate serde; -extern crate serde_bencode; +extern crate torrust_serde_bencode; #[macro_use] extern crate serde_derive; extern crate serde_bytes; -use serde_bencode::de; use serde_bytes::ByteBuf; use std::io::{self, Read}; +use torrust_serde_bencode::de; #[derive(Debug, Deserialize)] struct Node(String, i64); @@ -21,23 +21,23 @@ struct File { #[derive(Debug, Deserialize)] struct Info { - name: String, - pieces: ByteBuf, + pub name: String, + pub pieces: ByteBuf, #[serde(rename = "piece length")] - piece_length: i64, + pub piece_length: i64, #[serde(default)] - md5sum: Option, + pub md5sum: Option, #[serde(default)] - length: Option, + pub length: Option, #[serde(default)] - files: Option>, + pub files: Option>, #[serde(default)] - private: Option, + pub private: Option, #[serde(default)] - path: Option>, + pub path: Option>, #[serde(default)] #[serde(rename = "root hash")] - root_hash: Option, + pub root_hash: Option, } #[derive(Debug, Deserialize)] diff --git a/src/de.rs b/src/de.rs index 221d066..b785c81 100644 --- a/src/de.rs +++ b/src/de.rs @@ -9,7 +9,7 @@ use std::io::Read; use std::str; #[doc(hidden)] -// TODO: This should be pub(crate). +// todo: This should be pub(crate). pub struct BencodeAccess<'a, R: 'a + Read> { de: &'a mut Deserializer, len: Option, diff --git a/tests/tests.rs b/tests/tests.rs index 1fe76ec..bfa6d99 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,14 +1,14 @@ -extern crate serde_bencode; +extern crate torrust_serde_bencode; use serde::de::DeserializeOwned; use serde::Serialize; -use serde_bencode::de::{from_bytes, from_str}; -use serde_bencode::error::Result; -use serde_bencode::ser::{to_bytes, to_string, Serializer}; -use serde_bencode::value::Value; use serde_derive::{Deserialize, Serialize}; use std::collections::HashMap; use std::fmt::Debug; +use torrust_serde_bencode::de::{from_bytes, from_str}; +use torrust_serde_bencode::error::Result; +use torrust_serde_bencode::ser::{to_bytes, to_string, Serializer}; +use torrust_serde_bencode::value::Value; fn test_value_ser_de>(a: T) { let a = a.into();