From b85b2a4952b74073cf1b8c20e954ba1cb4f2f7e7 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Wed, 4 Oct 2023 09:42:25 +0200 Subject: [PATCH 1/5] chore: add code coverage dir to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4c277c1..a102dca 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.rustfmt Cargo.lock target + From 1eab404e11b684ce9731a2af8743d4eea6e2dd3e Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Wed, 4 Oct 2023 10:27:38 +0200 Subject: [PATCH 2/5] test: add unit tests to Value --- src/value.rs | 662 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 662 insertions(+) diff --git a/src/value.rs b/src/value.rs index 7540e38..d8c9c6f 100644 --- a/src/value.rs +++ b/src/value.rs @@ -157,3 +157,665 @@ impl From, Value>> for Value { Value::Dict(v) } } + +#[cfg(test)] +mod tests { + + fn assert_bytes_eq(actual: &[u8], expected: &[u8]) { + assert_eq!( + actual, + expected, + "expected {:?} to equal {:?}", + String::from_utf8_lossy(actual), + String::from_utf8_lossy(expected) + ); + } + + mod it_should_be_converted_from { + use std::collections::HashMap; + + use crate::value::Value; + + #[test] + fn an_i64() { + let value: Value = 11i64.into(); + assert_eq!(value, Value::Int(11)); + } + + #[test] + fn a_string() { + let value: Value = "11".into(); + assert_eq!(value, Value::Bytes(b"11".to_vec())); + } + + #[test] + fn a_str_reference() { + let value: Value = "11".to_string().into(); + assert_eq!(value, Value::Bytes(b"11".to_vec())); + } + + #[test] + fn a_byte_vector() { + let value: Value = vec![b'1', b'1'].into(); + assert_eq!(value, Value::Bytes(b"11".to_vec())); + } + + #[test] + fn a_vector_of_other_values() { + let value: Value = vec![Value::Bytes(b"11".to_vec())].into(); + assert_eq!(value, Value::List(vec!(Value::Bytes(b"11".to_vec())))); + } + + #[test] + fn a_hash_map_of_other_values() { + let value: Value = HashMap::from([(b"key".to_vec(), Value::Int(3))]).into(); + assert_eq!( + value, + Value::Dict(HashMap::from([(b"key".to_vec(), Value::Int(3))])) + ); + } + } + + mod for_serialization_and_deserialization_of_a { + mod byte_string { + + mod empty { + use crate::{from_bytes, Serializer}; + + use crate::value::tests::assert_bytes_eq; + use crate::value::Value; + use serde::Serialize; + + #[test] + fn serialization() { + let mut ser = Serializer::new(); + + let value = Value::Bytes(b"".to_vec()); + let _unused = value.serialize(&mut ser); + + assert_bytes_eq(ser.as_ref(), b"0:"); + } + + #[test] + fn deserialization() { + let value: Value = from_bytes(b"0:").unwrap(); + + assert_eq!(value, Value::Bytes(b"".to_vec())); + } + } + + mod non_empty { + use crate::{from_bytes, Serializer}; + + use crate::value::tests::assert_bytes_eq; + use crate::value::Value; + use serde::Serialize; + + #[test] + fn serialization() { + let mut ser = Serializer::new(); + + let value = Value::Bytes(b"spam".to_vec()); + let _unused = value.serialize(&mut ser); + + assert_bytes_eq(ser.as_ref(), b"4:spam"); + } + + #[test] + fn deserialization() { + let value: Value = from_bytes(b"4:spam").unwrap(); + + assert_eq!(value, Value::Bytes(b"spam".to_vec())); + } + } + } + + mod integer { + + mod positive { + use serde::Serialize; + + use crate::{ + from_bytes, + value::{tests::assert_bytes_eq, Value}, + Serializer, + }; + + #[test] + fn serialization() { + let mut ser = Serializer::new(); + + let value = Value::Int(3); + let _unused = value.serialize(&mut ser); + + assert_bytes_eq(ser.as_ref(), b"i3e"); + } + + #[test] + fn deserialization() { + let value: Value = from_bytes(b"i3e").unwrap(); + + assert_eq!(value, Value::Int(3)); + } + } + + mod negative { + use serde::Serialize; + + use crate::{ + from_bytes, + value::{tests::assert_bytes_eq, Value}, + Serializer, + }; + + #[test] + fn serialization() { + let mut ser = Serializer::new(); + + let value = Value::Int(-3); + let _unused = value.serialize(&mut ser); + + assert_bytes_eq(ser.as_ref(), b"i-3e"); + } + + #[test] + fn deserialization() { + let value: Value = from_bytes(b"i-3e").unwrap(); + + assert_eq!(value, Value::Int(-3)); + } + } + } + + mod list { + + mod empty { + use serde::Serialize; + + use crate::{ + from_bytes, + value::{tests::assert_bytes_eq, Value}, + Serializer, + }; + + #[test] + fn serialization() { + let mut ser = Serializer::new(); + + let value = Value::List(vec![]); + let _unused = value.serialize(&mut ser); + + assert_bytes_eq(ser.as_ref(), b"le"); + } + + #[test] + fn deserialization() { + let value: Value = from_bytes(b"le").unwrap(); + + assert_eq!(value, Value::List(vec![])); + } + } + + mod with_integers { + + mod with_one_integer { + use serde::Serialize; + + use crate::{ + from_bytes, + value::{tests::assert_bytes_eq, Value}, + Serializer, + }; + + #[test] + fn serialization() { + let mut ser = Serializer::new(); + + let value = Value::List(vec![Value::Int(3)]); + let _unused = value.serialize(&mut ser); + + assert_bytes_eq(ser.as_ref(), b"li3ee"); + } + + #[test] + fn deserialization() { + let value: Value = from_bytes(b"li3ee").unwrap(); + + assert_eq!(value, Value::List(vec![Value::Int(3)])); + } + } + + mod with_multiple_integers { + use serde::Serialize; + + use crate::{ + from_bytes, + value::{tests::assert_bytes_eq, Value}, + Serializer, + }; + + #[test] + fn serialization() { + let mut ser = Serializer::new(); + + let value = Value::List(vec![Value::Int(1), Value::Int(2)]); + let _unused = value.serialize(&mut ser); + + assert_bytes_eq(ser.as_ref(), b"li1ei2ee"); + } + + #[test] + fn deserialization() { + let value: Value = from_bytes(b"li1ei2ee").unwrap(); + + assert_eq!(value, Value::List(vec![Value::Int(1), Value::Int(2)])); + } + } + } + + mod with_byte_strings { + + mod empty { + use serde::Serialize; + + use crate::{ + from_bytes, + value::{tests::assert_bytes_eq, Value}, + Serializer, + }; + + #[test] + fn serialization() { + let mut ser = Serializer::new(); + + let value = Value::List(vec![Value::Bytes(b"".to_vec())]); + let _unused = value.serialize(&mut ser); + + assert_bytes_eq(ser.as_ref(), b"l0:e"); + } + + #[test] + fn deserialization() { + let value: Value = from_bytes(b"l0:e").unwrap(); + + assert_eq!(value, Value::List(vec![Value::Bytes(b"".to_vec())])); + } + } + + mod one_string { + use serde::Serialize; + + use crate::{ + from_bytes, + value::{tests::assert_bytes_eq, Value}, + Serializer, + }; + + #[test] + fn serialization() { + let mut ser = Serializer::new(); + + let value = Value::List(vec![Value::Bytes(b"spam".to_vec())]); + let _unused = value.serialize(&mut ser); + + // cspell: disable-next-line + assert_bytes_eq(ser.as_ref(), b"l4:spame"); + } + + #[test] + fn deserialization() { + // cspell: disable-next-line + let value: Value = from_bytes(b"l4:spame").unwrap(); + + assert_eq!(value, Value::List(vec![Value::Bytes(b"spam".to_vec())])); + } + } + + mod multiple_strings { + use serde::Serialize; + + use crate::{ + from_bytes, + value::{tests::assert_bytes_eq, Value}, + Serializer, + }; + + #[test] + fn serialization() { + let mut ser = Serializer::new(); + + let value = Value::List(vec![ + Value::Bytes(b"spam1".to_vec()), + Value::Bytes(b"spam1".to_vec()), + ]); + let _unused = value.serialize(&mut ser); + + assert_bytes_eq(ser.as_ref(), b"l5:spam15:spam1e"); + } + + #[test] + fn deserialization() { + let value: Value = from_bytes(b"l5:spam15:spam1e").unwrap(); + + assert_eq!( + value, + Value::List(vec![ + Value::Bytes(b"spam1".to_vec()), + Value::Bytes(b"spam1".to_vec()), + ]) + ); + } + } + } + + mod with_dictionaries { + + mod empty { + + use std::collections::HashMap; + + use serde::Serialize; + + use crate::{ + from_bytes, + value::{tests::assert_bytes_eq, Value}, + Serializer, + }; + + #[test] + fn serialization() { + let mut ser = Serializer::new(); + + let value = Value::List(vec![Value::Dict(HashMap::new())]); + let _unused = value.serialize(&mut ser); + + // cspell: disable-next-line + assert_bytes_eq(ser.as_ref(), b"ldee"); + } + + #[test] + fn deserialization() { + // cspell: disable-next-line + let value: Value = from_bytes(b"ldee").unwrap(); + + assert_eq!(value, Value::List(vec![Value::Dict(HashMap::new())])); + } + } + + mod non_empty { + use std::collections::HashMap; + + use serde::Serialize; + + use crate::{ + from_bytes, + value::{tests::assert_bytes_eq, Value}, + Serializer, + }; + + #[test] + fn serialization() { + let mut ser = Serializer::new(); + + let value = Value::List(vec![Value::Dict(HashMap::from([( + b"key".to_vec(), + Value::Int(3), + )]))]); + let _unused = value.serialize(&mut ser); + + // cspell: disable-next-line + assert_bytes_eq(ser.as_ref(), b"ld3:keyi3eee"); + } + + #[test] + fn deserialization() { + // cspell: disable-next-line + let value: Value = from_bytes(b"ld3:keyi3eee").unwrap(); + + assert_eq!( + value, + Value::List(vec![Value::Dict(HashMap::from([( + b"key".to_vec(), + Value::Int(3), + )]))]) + ); + } + } + } + } + + mod dictionary { + + mod empty { + use std::collections::HashMap; + + use serde::Serialize; + + use crate::{ + from_bytes, + value::{tests::assert_bytes_eq, Value}, + Serializer, + }; + + #[test] + fn serialization() { + let mut ser = Serializer::new(); + + let value = Value::Dict(HashMap::new()); + let _unused = value.serialize(&mut ser); + + assert_bytes_eq(ser.as_ref(), b"de"); + } + + #[test] + fn deserialization() { + let value: Value = from_bytes(b"de").unwrap(); + + assert_eq!(value, Value::Dict(HashMap::new())); + } + } + + mod with_integer_keys { + mod one_key { + use std::collections::HashMap; + + use serde::Serialize; + + use crate::{ + from_bytes, + value::{tests::assert_bytes_eq, Value}, + Serializer, + }; + + #[test] + fn serialization() { + let mut ser = Serializer::new(); + + let value = Value::Dict(HashMap::from([(b"key".to_vec(), Value::Int(3))])); + let _unused = value.serialize(&mut ser); + + // cspell: disable-next-line + assert_bytes_eq(ser.as_ref(), b"d3:keyi3ee"); + } + + #[test] + fn deserialization() { + // cspell: disable-next-line + let value: Value = from_bytes(b"d3:keyi3ee").unwrap(); + + assert_eq!( + value, + Value::Dict(HashMap::from([(b"key".to_vec(), Value::Int(3))])) + ); + } + } + + mod multiple_keys { + use std::collections::HashMap; + + use serde::Serialize; + + use crate::{ + from_bytes, + value::{tests::assert_bytes_eq, Value}, + Serializer, + }; + + #[test] + fn serialization() { + let mut ser = Serializer::new(); + + let value = Value::Dict(HashMap::from([ + (b"key1".to_vec(), Value::Int(1)), + (b"key2".to_vec(), Value::Int(2)), + ])); + let _unused = value.serialize(&mut ser); + + // cspell: disable-next-line + assert_bytes_eq(ser.as_ref(), b"d4:key1i1e4:key2i2ee"); + } + + #[test] + fn deserialization() { + // cspell: disable-next-line + let value: Value = from_bytes(b"d4:key1i1e4:key2i2ee").unwrap(); + + assert_eq!( + value, + Value::Dict(HashMap::from([ + (b"key1".to_vec(), Value::Int(1)), + (b"key2".to_vec(), Value::Int(2)), + ])) + ); + } + } + } + + mod with_byte_string_keys { + mod one_key { + use std::collections::HashMap; + + use serde::Serialize; + + use crate::{ + from_bytes, + value::{tests::assert_bytes_eq, Value}, + Serializer, + }; + + #[test] + fn serialization() { + let mut ser = Serializer::new(); + + let value = Value::Dict(HashMap::from([( + b"key".to_vec(), + Value::Bytes(b"spam".to_vec()), + )])); + let _unused = value.serialize(&mut ser); + + // cspell: disable-next-line + assert_bytes_eq(ser.as_ref(), b"d3:key4:spame"); + } + + #[test] + fn deserialization() { + // cspell: disable-next-line + let value: Value = from_bytes(b"d3:key4:spame").unwrap(); + + assert_eq!( + value, + Value::Dict(HashMap::from([( + b"key".to_vec(), + Value::Bytes(b"spam".to_vec()), + )])) + ); + } + } + + mod multiple_keys { + use std::collections::HashMap; + + use serde::Serialize; + + use crate::{ + from_bytes, + value::{tests::assert_bytes_eq, Value}, + Serializer, + }; + + #[test] + fn serialization() { + let mut ser = Serializer::new(); + + let value = Value::Dict(HashMap::from([ + (b"key1".to_vec(), Value::Bytes(b"spam1".to_vec())), + (b"key2".to_vec(), Value::Bytes(b"spam2".to_vec())), + ])); + let _unused = value.serialize(&mut ser); + + // cspell: disable-next-line + assert_bytes_eq(ser.as_ref(), b"d4:key15:spam14:key25:spam2e"); + } + + #[test] + fn deserialization() { + // cspell: disable-next-line + let value: Value = from_bytes(b"d4:key15:spam14:key25:spam2e").unwrap(); + + assert_eq!( + value, + Value::Dict(HashMap::from([ + (b"key1".to_vec(), Value::Bytes(b"spam1".to_vec())), + (b"key2".to_vec(), Value::Bytes(b"spam2".to_vec())), + ])) + ); + } + } + } + + mod with_list_keys { + mod empty { + use std::collections::HashMap; + + use serde::Serialize; + + use crate::{ + from_bytes, + value::{tests::assert_bytes_eq, Value}, + Serializer, + }; + + #[test] + fn serialization() { + let mut ser = Serializer::new(); + + let value = Value::Dict(HashMap::from([( + b"key".to_vec(), + Value::List(vec![Value::Int(1)]), + )])); + let _unused = value.serialize(&mut ser); + + // cspell: disable-next-line + assert_bytes_eq(ser.as_ref(), b"d3:keyli1eee"); + } + + #[test] + fn deserialization() { + // cspell: disable-next-line + let value: Value = from_bytes(b"d3:keyli1eee").unwrap(); + + assert_eq!( + value, + Value::Dict(HashMap::from([( + b"key".to_vec(), + Value::List(vec![Value::Int(1)]), + )])) + ); + } + } + + mod non_empty {} + } + } + } +} From f94c1982034bebd9c03943791e7fab5f0a795d14 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 9 Oct 2023 15:23:09 +0200 Subject: [PATCH 3/5] chore: add dev dependency serde_test --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index f8bcb46..33bef2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,4 @@ serde_bytes = "0.11" [dev-dependencies] serde_derive = "1.0" +serde_test = "1.0.176" From 983327478c7b0580db3df418685c0d4c45234e1f Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 9 Oct 2023 15:34:25 +0200 Subject: [PATCH 4/5] tests: add unit test for Value with serde_test --- src/value.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/value.rs b/src/value.rs index d8c9c6f..37cae80 100644 --- a/src/value.rs +++ b/src/value.rs @@ -160,6 +160,11 @@ impl From, Value>> for Value { #[cfg(test)] mod tests { + use std::collections::HashMap; + + use serde_test::{assert_tokens, Token}; + + use super::Value; fn assert_bytes_eq(actual: &[u8], expected: &[u8]) { assert_eq!( @@ -171,6 +176,44 @@ mod tests { ); } + #[test] + fn test_ser_de_bytes() { + let int = Value::Bytes(b"1".to_vec()); + + assert_tokens(&int, &[Token::Bytes(b"1")]); + } + + #[test] + fn test_ser_de_int() { + let int = Value::Int(1); + assert_tokens(&int, &[Token::I64(1)]); + } + + #[test] + fn test_ser_de_list() { + let int = Value::List(vec![Value::Int(1)]); + + assert_tokens( + &int, + &[Token::Seq { len: Some(1) }, Token::I64(1), Token::SeqEnd], + ); + } + + #[test] + fn test_ser_de_dict() { + let dict = Value::Dict(HashMap::from([(b"key".to_vec(), Value::Int(1))])); + + assert_tokens( + &dict, + &[ + Token::Map { len: Some(1) }, + Token::Bytes(b"key"), + Token::I64(1), + Token::MapEnd, + ], + ); + } + mod it_should_be_converted_from { use std::collections::HashMap; From f58baf7527cebc27e579415bcc2b3a409771b567 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 9 Oct 2023 15:42:21 +0200 Subject: [PATCH 5/5] chore: undo package rename THe initial intention was to mantain a fork, but finally we will merge the fork changes into the upstream repo. --- Cargo.toml | 6 +++--- README.md | 4 +--- benches/benches.rs | 4 ++-- examples/parse_torrent.rs | 2 +- fuzz/Cargo.toml | 4 ++-- fuzz/fuzz_targets/from_bytes.rs | 4 ++-- src/de.rs | 8 ++++---- src/error.rs | 2 +- src/lib.rs | 4 ++-- src/ser.rs | 8 ++++---- tests/tests.rs | 12 ++++++------ 11 files changed, 28 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 33bef2e..0cd4096 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [package] -name = "torrust-serde-bencode" +name = "serde_bencode" description = "A Serde backed Bencode encoding/decoding library for Rust." version = "0.2.3" authors = ["Toby Padilla ", "Nautilus Cyberneering "] -repository = "https://github.com/torrust/torrust-serde-bencode" -documentation = "https://docs.rs/torrust-serde-bencode/" +repository = "https://github.com/toby/serde-bencode" +documentation = "https://docs.rs/serde_bencode/" license = "MIT" keywords = ["bencode", "serialize", "deserialize", "serde"] edition = "2018" diff --git a/README.md b/README.md index 314948d..298d69a 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,10 @@ # 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) +[![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) 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`: diff --git a/benches/benches.rs b/benches/benches.rs index cefb3d1..239501d 100644 --- a/benches/benches.rs +++ b/benches/benches.rs @@ -5,9 +5,9 @@ extern crate test; extern crate serde_derive; use serde::Serialize; +use serde_bencode::de::from_bytes; +use serde_bencode::ser::Serializer; use test::Bencher; -use torrust_serde_bencode::de::from_bytes; -use torrust_serde_bencode::ser::Serializer; #[bench] fn ser_de_simple(b: &mut Bencher) { diff --git a/examples/parse_torrent.rs b/examples/parse_torrent.rs index 323187e..36395d7 100644 --- a/examples/parse_torrent.rs +++ b/examples/parse_torrent.rs @@ -1,9 +1,9 @@ #[macro_use] extern crate serde_derive; +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); diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 88a7347..cdf61fc 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "torrust_serde_bencode_fuzz" +name = "serde_bencode_fuzz" version = "0.0.0" authors = ["Automatically generated"] publish = false @@ -11,7 +11,7 @@ cargo-fuzz = true [dependencies] libfuzzer-sys = "0.4" -[dependencies.torrust_serde_bencode] +[dependencies.serde_bencode] path = ".." # Prevent this from interfering with workspaces diff --git a/fuzz/fuzz_targets/from_bytes.rs b/fuzz/fuzz_targets/from_bytes.rs index 3e4b345..3a93ec4 100644 --- a/fuzz/fuzz_targets/from_bytes.rs +++ b/fuzz/fuzz_targets/from_bytes.rs @@ -1,8 +1,8 @@ #![no_main] use libfuzzer_sys::fuzz_target; -use torrust_serde_bencode::from_bytes; -use torrust_serde_bencode::value::Value; +use serde_bencode::from_bytes; +use serde_bencode::value::Value; fuzz_target!(|data: &[u8]| { let _: Result = from_bytes(data); diff --git a/src/de.rs b/src/de.rs index 350aa3f..24c5164 100644 --- a/src/de.rs +++ b/src/de.rs @@ -345,7 +345,7 @@ impl<'de, 'a, R: Read> de::Deserializer<'de> for &'a mut Deserializer { /// /// # Examples /// ``` -/// # fn main() -> Result<(), torrust_serde_bencode::Error> { +/// # fn main() -> Result<(), serde_bencode::Error> { /// use serde_derive::{Serialize, Deserialize}; /// /// #[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] @@ -355,7 +355,7 @@ impl<'de, 'a, R: Read> de::Deserializer<'de> for &'a mut Deserializer { /// } /// /// let encoded = "d4:city18:Duckburg, Calisota6:street17:1313 Webfoot Walke".to_string(); -/// let decoded: Address = torrust_serde_bencode::from_str(&encoded)?; +/// let decoded: Address = serde_bencode::from_str(&encoded)?; /// /// assert_eq!( /// decoded, @@ -384,7 +384,7 @@ where /// /// # Examples /// ``` -/// # fn main() -> Result<(), torrust_serde_bencode::Error> { +/// # fn main() -> Result<(), serde_bencode::Error> { /// use serde_derive::{Serialize, Deserialize}; /// /// #[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] @@ -394,7 +394,7 @@ where /// } /// /// let encoded = "d4:city18:Duckburg, Calisota6:street17:1313 Webfoot Walke".as_bytes(); -/// let decoded: Address = torrust_serde_bencode::from_bytes(&encoded)?; +/// let decoded: Address = serde_bencode::from_bytes(&encoded)?; /// /// assert_eq!( /// decoded, diff --git a/src/error.rs b/src/error.rs index b336966..53e4da5 100644 --- a/src/error.rs +++ b/src/error.rs @@ -9,7 +9,7 @@ use std::fmt::Display; use std::io::Error as IoError; use std::result::Result as StdResult; -/// Alias for `Result`. +/// Alias for `Result`. pub type Result = StdResult; /// Represents all possible errors which can occur when serializing or deserializing bencode. diff --git a/src/lib.rs b/src/lib.rs index d37df03..27acd02 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,12 +18,12 @@ //! price: 130, //! }; //! -//! let serialized = torrust_serde_bencode::to_string(&apple)?; +//! let serialized = serde_bencode::to_string(&apple)?; //! //! // cspell:disable-next-line //! assert_eq!(serialized, "d4:name5:Apple5:pricei130ee".to_string()); //! -//! let deserialized: Product = torrust_serde_bencode::from_str(&serialized)?; +//! let deserialized: Product = serde_bencode::from_str(&serialized)?; //! //! assert_eq!( //! deserialized, diff --git a/src/ser.rs b/src/ser.rs index ca3ebb9..5f5d555 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -351,7 +351,7 @@ impl<'a> ser::Serializer for &'a mut Serializer { /// /// # Examples /// ``` -/// # fn main() -> Result<(), torrust_serde_bencode::Error> { +/// # fn main() -> Result<(), serde_bencode::Error> { /// use serde_derive::{Serialize, Deserialize}; /// /// #[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] @@ -365,7 +365,7 @@ impl<'a> ser::Serializer for &'a mut Serializer { /// city: "Duckburg, Calisota".to_string(), /// }; /// -/// let bytes = torrust_serde_bencode::to_bytes(&address)?; +/// let bytes = serde_bencode::to_bytes(&address)?; /// assert_eq!( /// String::from_utf8(bytes).unwrap(), /// "d4:city18:Duckburg, Calisota6:street17:1313 Webfoot Walke", @@ -388,7 +388,7 @@ pub fn to_bytes(b: &T) -> Result> { /// /// # Examples /// ``` -/// # fn main() -> Result<(), torrust_serde_bencode::Error> { +/// # fn main() -> Result<(), serde_bencode::Error> { /// use serde_derive::{Serialize, Deserialize}; /// /// #[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] @@ -403,7 +403,7 @@ pub fn to_bytes(b: &T) -> Result> { /// }; /// /// assert_eq!( -/// torrust_serde_bencode::to_string(&address)?, +/// serde_bencode::to_string(&address)?, /// "d4:city18:Duckburg, Calisota6:street17:1313 Webfoot Walke".to_string(), /// ); /// # Ok(()) diff --git a/tests/tests.rs b/tests/tests.rs index dc1312f..4dccde9 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,12 +1,12 @@ 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) { // Serialize @@ -617,13 +617,13 @@ fn deserialize_too_long_byte_string() { } mod torrent_file { + use serde_bencode::de::{self, from_str}; + use serde_bencode::ser::to_string; use serde_bytes::ByteBuf; use serde_derive::{Deserialize, Serialize}; use std::fmt::Debug; use std::fs; use std::io::Read; - use torrust_serde_bencode::de::{self, from_str}; - use torrust_serde_bencode::ser::to_string; #[test] fn serialization() {