torrust / torrust-serde-bencode-archive Goto Github PK
View Code? Open in Web Editor NEWThis project forked from toby/serde-bencode
Serde backed Bencode encoding/decoding library for Rust.
License: MIT License
This project forked from toby/serde-bencode
Serde backed Bencode encoding/decoding library for Rust.
License: MIT License
I think these two failing tests could be the same problem because they both use #[serde(flatten)]
for an enum
field.
cargo test ser_de_flattened_enum -- --nocapture
cargo test ser_de_flattened_adjacently_tagged_enum -- --nocapture
$ cargo test ser_de_flattened_enum -- --nocapture
Finished test [unoptimized + debuginfo] target(s) in 0.00s
Running unittests src/lib.rs (target/debug/deps/torrust_serde_bencode-61b7eea2ea5618bf)
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Running tests/tests.rs (target/debug/deps/tests-b55451bec73c8180)
running 1 test
bytes: "d12:message_type8:Responsee"
bytes: "d12:message_type8:Responsee"
thread 'ser_de_flattened_enum' panicked at tests/tests.rs:34:41:
called `Result::unwrap()` on an `Err` value: InvalidType("Invalid Type: byte array (expected: `string or map`)")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test ser_de_flattened_enum ... FAILED
failures:
failures:
ser_de_flattened_enum
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 42 filtered out; finished in 0.00s
error: test failed, to rerun pass `--test tests`
$ cargo test ser_de_flattened_adjacently_tagged_enum -- --nocapture
Finished test [unoptimized + debuginfo] target(s) in 0.00s
Running unittests src/lib.rs (target/debug/deps/torrust_serde_bencode-61b7eea2ea5618bf)
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Running tests/tests.rs (target/debug/deps/tests-b55451bec73c8180)
running 1 test
bytes: "d7:contentd5:tokeni456ee2:idi123e4:type7:Requeste"
thread 'ser_de_flattened_adjacently_tagged_enum' panicked at tests/tests.rs:34:41:
called `Result::unwrap()` on an `Err` value: InvalidType("Invalid Type: byte array (expected: `string or map`)")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test ser_de_flattened_adjacently_tagged_enum ... FAILED
failures:
failures:
ser_de_flattened_adjacently_tagged_enum
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 42 filtered out; finished in 0.00s
error: test failed, to rerun pass `--test tests`
Current coverage report:
Filename Regions Missed Regions Cover Functions Missed Functions Executed Lines Missed Lines Cover Branches Missed Branches Cover
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
de.rs 190 60 68.42% 36 9 75.00% 237 43 81.86% 0 0 -
error.rs 31 31 0.00% 12 12 0.00% 51 51 0.00% 0 0 -
ser.rs 118 43 63.56% 57 13 77.19% 277 59 78.70% 0 0 -
ser/string.rs 30 28 6.67% 30 28 6.67% 125 119 4.80% 0 0 -
value.rs 55 16 70.91% 19 8 57.89% 86 23 73.26% 0 0 -
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL 424 178 58.02% 154 70 54.55% 776 295 61.98% 0 0 -
Relates to: torrust/torrust-index#266
There is a failing test:
#[test]
fn deserialize_to_nested_list() {
// [
// [
// "188.163.121.224",
// 56711
// ],
// [
// "162.250.131.26",
// 13386
// ]
// ]
#[derive(PartialEq, Debug, Deserialize)]
struct Item {
ip: String,
port: i64,
}
let b = "d1:0l15:188.163.121.224i56711ee1:1l14:162.250.131.26i13386eee";
let r: Vec<Item> = from_str(b).unwrap();
assert_eq!(
r,
vec![
Item {
ip: "188.163.121.224".to_string(),
port: 56711
},
Item {
ip: "162.250.131.26".to_string(),
port: 13386
}
]
);
}
$ cargo build
Compiling torrust-serde-bencode v0.2.3 (/home/josecelano/Documents/git/committer/me/github/torrust/torrust-serde-bencode)
error: hidden lifetime parameters in types are deprecated
--> src/error.rs:64:28
|
64 | fn invalid_type(unexp: Unexpected, exp: &dyn Expected) -> Self {
| ^^^^^^^^^^ expected lifetime parameter
|
= note: `-D elided-lifetimes-in-paths` implied by `-D rust-2018-idioms`
= help: to override `-D rust-2018-idioms` add `#[allow(elided_lifetimes_in_paths)]`
help: indicate the anonymous lifetime
|
64 | fn invalid_type(unexp: Unexpected<'_>, exp: &dyn Expected) -> Self {
| ++++
error: hidden lifetime parameters in types are deprecated
--> src/error.rs:68:29
|
68 | fn invalid_value(unexp: Unexpected, exp: &dyn Expected) -> Self {
| ^^^^^^^^^^ expected lifetime parameter
|
help: indicate the anonymous lifetime
|
68 | fn invalid_value(unexp: Unexpected<'_>, exp: &dyn Expected) -> Self {
| ++++
error: hidden lifetime parameters in types are deprecated
--> src/error.rs:109:32
|
109 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
| -----^^^^^^^^^
| |
| expected lifetime parameter
|
help: indicate the anonymous lifetime
|
109 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
| ++++
error: hidden lifetime parameters in types are deprecated
--> src/ser/string.rs:11:40
|
11 | fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
| -----^^^^^^^^^
| |
| expected lifetime parameter
|
help: indicate the anonymous lifetime
|
11 | fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
| ++++
error: hidden lifetime parameters in types are deprecated
--> src/ser/string.rs:16:29
|
16 | fn unexpected<T>(unexp: de::Unexpected) -> Result<T> {
| ----^^^^^^^^^^
| |
| expected lifetime parameter
|
help: indicate the anonymous lifetime
|
16 | fn unexpected<T>(unexp: de::Unexpected<'_>) -> Result<T> {
| ++++
error: hidden lifetime parameters in types are deprecated
--> src/ser.rs:93:56
|
93 | pub fn new(ser: &'a mut Serializer, len: usize) -> SerializeMap {
| ^^^^^^^^^^^^ expected lifetime parameter
|
help: indicate the anonymous lifetime
|
93 | pub fn new(ser: &'a mut Serializer, len: usize) -> SerializeMap<'_> {
| ++++
error: hidden lifetime parameters in types are deprecated
--> src/value.rs:57:46
|
57 | fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
| -----^^^^^^^^^
| |
| expected lifetime parameter
|
help: indicate the anonymous lifetime
|
57 | fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
| ++++
error: outlives requirements can be inferred
--> src/de.rs:14:33
|
14 | pub struct BencodeAccess<'a, R: 'a + Read> {
| ^^^^^ help: remove this bound
|
= note: `-D explicit-outlives-requirements` implied by `-D rust-2018-idioms`
= help: to override `-D rust-2018-idioms` add `#[allow(explicit_outlives_requirements)]`
error: could not compile `torrust-serde-bencode` (lib) due to 8 previous errors
Checking torrust-serde-bencode v0.2.3 (/home/josecelano/Documents/git/committer/me/github/torrust/torrust-serde-bencode)
error: variables can be used directly in the `format!` string
--> src/de.rs:122:42
|
122 | t => Err(Error::InvalidValue(format!(
| __________________________________________^
123 | | "Expected bytes or map; got `{:?}`",
124 | | t
125 | | ))),
| |_____________^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
= note: `-D clippy::uninlined-format-args` implied by `-D clippy::pedantic`
= help: to override `-D clippy::pedantic` add `#[allow(clippy::uninlined_format_args)]`
error: variables can be used directly in the `format!` string
--> src/de.rs:149:40
|
149 | Self::End => Error::custom(format_args!("unexpected end, expected {}", expected)),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
help: change this to
|
149 - Self::End => Error::custom(format_args!("unexpected end, expected {}", expected)),
149 + Self::End => Error::custom(format_args!("unexpected end, expected {expected}")),
|
error: this lifetime isn't used in the impl
--> src/de.rs:161:6
|
161 | impl<'de, R: Read> Deserializer<R> {
| ^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes
= note: `-D clippy::extra-unused-lifetimes` implied by `-D clippy::complexity`
= help: to override `-D clippy::complexity` add `#[allow(clippy::extra_unused_lifetimes)]`
error: variables can be used directly in the `format!` string
--> src/de.rs:180:45
|
180 | Error::InvalidValue(format!("Can't parse `{}` as integer", len_str))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
help: change this to
|
180 - Error::InvalidValue(format!("Can't parse `{}` as integer", len_str))
180 + Error::InvalidValue(format!("Can't parse `{len_str}` as integer"))
|
error: variables can be used directly in the `format!` string
--> src/de.rs:203:45
|
203 | Error::InvalidValue(format!("Can't parse `{}` as string length", len_str))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
help: change this to
|
203 - Error::InvalidValue(format!("Can't parse `{}` as string length", len_str))
203 + Error::InvalidValue(format!("Can't parse `{len_str}` as string length"))
|
error: this expression creates a reference which is immediately dereferenced by the compiler
--> src/de.rs:262:71
|
262 | ParseResult::List => visitor.visit_seq(BencodeAccess::new(&mut self, None)),
| ^^^^^^^^^ help: change this to: `self`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
= note: `-D clippy::needless-borrow` implied by `-D clippy::style`
= help: to override `-D clippy::style` add `#[allow(clippy::needless_borrow)]`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> src/de.rs:263:70
|
263 | ParseResult::Map => visitor.visit_map(BencodeAccess::new(&mut self, None)),
| ^^^^^^^^^ help: change this to: `self`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
error: this match arm has an identical body to another arm
--> src/error.rs:110:13
|
110 | Error::InvalidType(ref s) => s,
| -------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::InvalidType(ref s) | Error::InvalidValue(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:111:13
|
111 | Error::InvalidValue(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
= note: `-D clippy::match-same-arms` implied by `-D clippy::pedantic`
= help: to override `-D clippy::pedantic` add `#[allow(clippy::match_same_arms)]`
error: this match arm has an identical body to another arm
--> src/error.rs:110:13
|
110 | Error::InvalidType(ref s) => s,
| -------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::InvalidType(ref s) | Error::InvalidLength(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:112:13
|
112 | Error::InvalidLength(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:111:13
|
111 | Error::InvalidValue(ref s) => s,
| --------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::InvalidValue(ref s) | Error::InvalidLength(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:112:13
|
112 | Error::InvalidLength(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:110:13
|
110 | Error::InvalidType(ref s) => s,
| -------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::InvalidType(ref s) | Error::UnknownVariant(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:113:13
|
113 | Error::UnknownVariant(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:111:13
|
111 | Error::InvalidValue(ref s) => s,
| --------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::InvalidValue(ref s) | Error::UnknownVariant(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:113:13
|
113 | Error::UnknownVariant(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:112:13
|
112 | Error::InvalidLength(ref s) => s,
| ---------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::InvalidLength(ref s) | Error::UnknownVariant(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:113:13
|
113 | Error::UnknownVariant(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:110:13
|
110 | Error::InvalidType(ref s) => s,
| -------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::InvalidType(ref s) | Error::UnknownField(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:114:13
|
114 | Error::UnknownField(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:111:13
|
111 | Error::InvalidValue(ref s) => s,
| --------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::InvalidValue(ref s) | Error::UnknownField(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:114:13
|
114 | Error::UnknownField(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:112:13
|
112 | Error::InvalidLength(ref s) => s,
| ---------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::InvalidLength(ref s) | Error::UnknownField(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:114:13
|
114 | Error::UnknownField(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:113:13
|
113 | Error::UnknownVariant(ref s) => s,
| ----------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::UnknownVariant(ref s) | Error::UnknownField(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:114:13
|
114 | Error::UnknownField(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:110:13
|
110 | Error::InvalidType(ref s) => s,
| -------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::InvalidType(ref s) | Error::MissingField(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:115:13
|
115 | Error::MissingField(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:111:13
|
111 | Error::InvalidValue(ref s) => s,
| --------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::InvalidValue(ref s) | Error::MissingField(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:115:13
|
115 | Error::MissingField(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:112:13
|
112 | Error::InvalidLength(ref s) => s,
| ---------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::InvalidLength(ref s) | Error::MissingField(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:115:13
|
115 | Error::MissingField(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:113:13
|
113 | Error::UnknownVariant(ref s) => s,
| ----------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::UnknownVariant(ref s) | Error::MissingField(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:115:13
|
115 | Error::MissingField(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:114:13
|
114 | Error::UnknownField(ref s) => s,
| --------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::UnknownField(ref s) | Error::MissingField(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:115:13
|
115 | Error::MissingField(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:110:13
|
110 | Error::InvalidType(ref s) => s,
| -------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::InvalidType(ref s) | Error::DuplicateField(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:116:13
|
116 | Error::DuplicateField(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:111:13
|
111 | Error::InvalidValue(ref s) => s,
| --------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::InvalidValue(ref s) | Error::DuplicateField(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:116:13
|
116 | Error::DuplicateField(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:112:13
|
112 | Error::InvalidLength(ref s) => s,
| ---------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::InvalidLength(ref s) | Error::DuplicateField(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:116:13
|
116 | Error::DuplicateField(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:113:13
|
113 | Error::UnknownVariant(ref s) => s,
| ----------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::UnknownVariant(ref s) | Error::DuplicateField(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:116:13
|
116 | Error::DuplicateField(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:114:13
|
114 | Error::UnknownField(ref s) => s,
| --------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::UnknownField(ref s) | Error::DuplicateField(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:116:13
|
116 | Error::DuplicateField(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:115:13
|
115 | Error::MissingField(ref s) => s,
| --------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::MissingField(ref s) | Error::DuplicateField(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:116:13
|
116 | Error::DuplicateField(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:110:13
|
110 | Error::InvalidType(ref s) => s,
| -------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::InvalidType(ref s) | Error::Custom(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:117:13
|
117 | Error::Custom(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:111:13
|
111 | Error::InvalidValue(ref s) => s,
| --------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::InvalidValue(ref s) | Error::Custom(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:117:13
|
117 | Error::Custom(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:112:13
|
112 | Error::InvalidLength(ref s) => s,
| ---------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::InvalidLength(ref s) | Error::Custom(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:117:13
|
117 | Error::Custom(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:113:13
|
113 | Error::UnknownVariant(ref s) => s,
| ----------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::UnknownVariant(ref s) | Error::Custom(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:117:13
|
117 | Error::Custom(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:114:13
|
114 | Error::UnknownField(ref s) => s,
| --------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::UnknownField(ref s) | Error::Custom(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:117:13
|
117 | Error::Custom(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:115:13
|
115 | Error::MissingField(ref s) => s,
| --------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::MissingField(ref s) | Error::Custom(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:117:13
|
117 | Error::Custom(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: this match arm has an identical body to another arm
--> src/error.rs:116:13
|
116 | Error::DuplicateField(ref s) => s,
| ----------------------------^^^^^
| |
| help: try merging the arm patterns: `Error::DuplicateField(ref s) | Error::Custom(ref s)`
|
= help: or try changing either arm body
note: other arm here
--> src/error.rs:117:13
|
117 | Error::Custom(ref s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
error: item name starts with its containing module's name
--> src/ser/string.rs:25:12
|
25 | pub struct StringSerializer;
| ^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#module_name_repetitions
= note: `-D clippy::module-name-repetitions` implied by `-D clippy::pedantic`
= help: to override `-D clippy::pedantic` add `#[allow(clippy::module_name_repetitions)]`
error: casting `i8` to `i64` may become silently lossy if you later change the type
--> src/ser/string.rs:42:28
|
42 | self.serialize_i64(value as i64)
| ^^^^^^^^^^^^ help: try: `i64::from(value)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless
= note: `-D clippy::cast-lossless` implied by `-D clippy::pedantic`
= help: to override `-D clippy::pedantic` add `#[allow(clippy::cast_lossless)]`
error: casting `i16` to `i64` may become silently lossy if you later change the type
--> src/ser/string.rs:45:28
|
45 | self.serialize_i64(value as i64)
| ^^^^^^^^^^^^ help: try: `i64::from(value)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless
error: casting `i32` to `i64` may become silently lossy if you later change the type
--> src/ser/string.rs:48:28
|
48 | self.serialize_i64(value as i64)
| ^^^^^^^^^^^^ help: try: `i64::from(value)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless
error: casting `u8` to `u64` may become silently lossy if you later change the type
--> src/ser/string.rs:54:28
|
54 | self.serialize_u64(value as u64)
| ^^^^^^^^^^^^ help: try: `u64::from(value)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless
error: casting `u16` to `u64` may become silently lossy if you later change the type
--> src/ser/string.rs:57:28
|
57 | self.serialize_u64(value as u64)
| ^^^^^^^^^^^^ help: try: `u64::from(value)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless
error: casting `u32` to `u64` may become silently lossy if you later change the type
--> src/ser/string.rs:60:28
|
60 | self.serialize_u64(value as u64)
| ^^^^^^^^^^^^ help: try: `u64::from(value)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless
error: casting `f32` to `f64` may become silently lossy if you later change the type
--> src/ser/string.rs:66:28
|
66 | self.serialize_f64(value as f64)
| ^^^^^^^^^^^^ help: try: `f64::from(value)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless
error: this method could have a `#[must_use]` attribute
--> src/ser.rs:18:5
|
18 | pub fn new() -> Serializer {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn new() -> Serializer`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate
= note: `-D clippy::must-use-candidate` implied by `-D clippy::pedantic`
= help: to override `-D clippy::pedantic` add `#[allow(clippy::must_use_candidate)]`
error: this method could have a `#[must_use]` attribute
--> src/ser.rs:23:5
|
23 | pub fn into_vec(self) -> Vec<u8> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn into_vec(self) -> Vec<u8>`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate
error: dereferencing a tuple pattern where every element takes a reference
--> src/ser.rs:108:26
|
108 | entries.sort_by(|&(ref a, _), &(ref b, _)| a.cmp(b));
| ^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrowed_reference
= note: `-D clippy::needless-borrowed-reference` implied by `-D clippy::complexity`
= help: to override `-D clippy::complexity` add `#[allow(clippy::needless_borrowed_reference)]`
help: try removing the `&` and `ref` parts
|
108 - entries.sort_by(|&(ref a, _), &(ref b, _)| a.cmp(b));
108 + entries.sort_by(|(a, _), &(ref b, _)| a.cmp(b));
|
error: dereferencing a tuple pattern where every element takes a reference
--> src/ser.rs:108:39
|
108 | entries.sort_by(|&(ref a, _), &(ref b, _)| a.cmp(b));
| ^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrowed_reference
help: try removing the `&` and `ref` parts
|
108 - entries.sort_by(|&(ref a, _), &(ref b, _)| a.cmp(b));
108 + entries.sort_by(|&(ref a, _), (b, _)| a.cmp(b));
|
error: casting `bool` to `i64` is more cleanly stated with `i64::from(_)`
--> src/ser.rs:215:28
|
215 | self.serialize_i64(value as i64)
| ^^^^^^^^^^^^ help: try: `i64::from(value)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless
error: casting `i8` to `i64` may become silently lossy if you later change the type
--> src/ser.rs:218:28
|
218 | self.serialize_i64(value as i64)
| ^^^^^^^^^^^^ help: try: `i64::from(value)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless
error: casting `i16` to `i64` may become silently lossy if you later change the type
--> src/ser.rs:221:28
|
221 | self.serialize_i64(value as i64)
| ^^^^^^^^^^^^ help: try: `i64::from(value)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless
error: casting `i32` to `i64` may become silently lossy if you later change the type
--> src/ser.rs:224:28
|
224 | self.serialize_i64(value as i64)
| ^^^^^^^^^^^^ help: try: `i64::from(value)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless
error: casting `u8` to `u64` may become silently lossy if you later change the type
--> src/ser.rs:233:28
|
233 | self.serialize_u64(value as u64)
| ^^^^^^^^^^^^ help: try: `u64::from(value)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless
error: casting `u16` to `u64` may become silently lossy if you later change the type
--> src/ser.rs:236:28
|
236 | self.serialize_u64(value as u64)
| ^^^^^^^^^^^^ help: try: `u64::from(value)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless
error: casting `u32` to `u64` may become silently lossy if you later change the type
--> src/ser.rs:239:28
|
239 | self.serialize_u64(value as u64)
| ^^^^^^^^^^^^ help: try: `u64::from(value)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless
error: redundant closure
--> src/ser.rs:419:14
|
419 | .map(|s| s.to_string())
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::string::ToString::to_string`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls
= note: `-D clippy::redundant-closure-for-method-calls` implied by `-D clippy::pedantic`
= help: to override `-D clippy::pedantic` add `#[allow(clippy::redundant_closure_for_method_calls)]`
error: casting `u64` to `i64` may wrap around the value
--> src/value.rs:68:23
|
68 | Ok(Value::Int(value as i64))
| ^^^^^^^^^^^^
|
= note: `-D clippy::cast-possible-wrap` implied by `-D clippy::pedantic`
= help: to override `-D clippy::pedantic` add `#[allow(clippy::cast_possible_wrap)]`
error: could not compile `torrust-serde-bencode` (lib test) due to 56 previous errors
warning: build failed, waiting for other jobs to finish...
error: could not compile `torrust-serde-bencode` (lib) due to 56 previous errors
Relates to: #12
It seems you can not deserialize a tuple struct like this struct Node(String, i64)
from a nested list in encoded format. There are already two tests for this behavior.
#[test]
fn deserialization() {
// todo: you cannot deserialize to the same struct used in serialization.
// It does not work with a tuple struct `struct Node(String, i64)`
// instead of a tuple `(String, i64)`.
#[allow(dead_code)]
#[derive(PartialEq, Debug, Serialize, Deserialize)]
struct Torrent {
info: Info,
#[serde(default)]
nodes: Option<Vec<(String, i64)>>,
}
#[allow(dead_code)]
#[derive(PartialEq, Debug, Serialize, Deserialize)]
struct Info {
#[serde(default)]
pub length: Option<i64>,
#[serde(default)]
pub name: String,
#[serde(rename = "piece length")]
pub piece_length: i64,
#[serde(default)]
pub pieces: ByteBuf,
}
#[derive(PartialEq, Debug, Serialize, Deserialize)]
struct Node(String, i64);
// cspell:disable-next-line
let b = "d4:infod6:lengthi8e4:name11:minimal.txt12:piece lengthi1e6:pieces1:pe5:nodesll15:188.163.121.224i56711eel14:162.250.131.26i13386eeee";
let r: Torrent = from_str(b).unwrap();
assert_eq!(
r,
Torrent {
info: Info {
name: "minimal.txt".to_string(),
pieces: ByteBuf::from(vec![b'p']),
piece_length: 1,
length: Some(8),
},
nodes: Some(vec![
("188.163.121.224".to_string(), 56711),
("162.250.131.26".to_string(), 13386),
]),
}
);
}
Although you can serialize them:
#[test]
fn serialization() {
#[allow(dead_code)]
#[derive(PartialEq, Debug, Serialize, Deserialize)]
struct Torrent {
info: Info,
#[serde(default)]
nodes: Option<Vec<Node>>,
}
#[allow(dead_code)]
#[derive(PartialEq, Debug, Serialize, Deserialize)]
struct Info {
#[serde(default)]
pub length: Option<i64>,
#[serde(default)]
pub name: String,
#[serde(rename = "piece length")]
pub piece_length: i64,
#[serde(default)]
pub pieces: ByteBuf,
}
#[derive(PartialEq, Debug, Serialize, Deserialize)]
struct Node(String, i64);
let torrent = Torrent {
info: Info {
name: "minimal.txt".to_string(),
pieces: ByteBuf::from(vec![b'p']),
piece_length: 1,
length: Some(8),
},
nodes: Some(vec![
Node("188.163.121.224".to_string(), 56711),
Node("162.250.131.26".to_string(), 13386),
]),
};
// cspell:disable-next-line
assert_eq!(to_string(&torrent).unwrap(), "d4:infod6:lengthi8e4:name11:minimal.txt12:piece lengthi1e6:pieces1:pe5:nodesll15:188.163.121.224i56711eel14:162.250.131.26i13386eeee");
}
Both options:
nodes: Option<Vec<Node>>,
where Node
is struct Node(String, i64)
nodes: Option<Vec<(String, i64)>>,
produce the same bencoded, but you can only deserialize the second one. The first one gives you only one item in the parent list (one node).
I am still determining if that's a bug. As bencoded format is ordered, there should be no problem assigning the values to the tuple struct fields (0 and 1). The first value should be assigned to the first element in the tuple.
Anyway, ti seems the problem is not even in this package but when the series values are mapped to the final struct (not sure).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.