diff --git a/cSpell.json b/cSpell.json index 299e9bb..ec5e8ca 100644 --- a/cSpell.json +++ b/cSpell.json @@ -1,6 +1,7 @@ { "words": [ "bencoded", + "httpseeds", "Serde" ], "enableFiletypes": [ diff --git a/examples/parse_torrent.rs b/examples/parse_torrent.rs index ae60862..a3590cc 100644 --- a/examples/parse_torrent.rs +++ b/examples/parse_torrent.rs @@ -1,8 +1,5 @@ -extern crate serde; -extern crate torrust_serde_bencode; #[macro_use] extern crate serde_derive; -extern crate serde_bytes; use serde_bytes::ByteBuf; use std::io::{self, Read}; @@ -19,6 +16,7 @@ struct File { md5sum: Option, } +#[allow(dead_code)] #[derive(Debug, Deserialize)] struct Info { pub name: String, diff --git a/src/de.rs b/src/de.rs index 49db990..f0b882d 100644 --- a/src/de.rs +++ b/src/de.rs @@ -11,7 +11,7 @@ use std::str; #[doc(hidden)] // todo: This should be pub(crate). -pub struct BencodeAccess<'a, R: 'a + Read> { +pub struct BencodeAccess<'a, R: Read> { de: &'a mut Deserializer, len: Option, } diff --git a/src/error.rs b/src/error.rs index beb9acb..421ce6b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -61,38 +61,36 @@ impl DeError for Error { Error::Custom(msg.to_string()) } - fn invalid_type(unexp: Unexpected, exp: &dyn Expected) -> Self { - Error::InvalidType(format!("Invalid Type: {} (expected: `{}`)", unexp, exp)) + fn invalid_type(unexpected: Unexpected<'_>, exp: &dyn Expected) -> Self { + Error::InvalidType(format!("Invalid Type: {unexpected} (expected: `{exp}`)")) } - fn invalid_value(unexp: Unexpected, exp: &dyn Expected) -> Self { - Error::InvalidValue(format!("Invalid Value: {} (expected: `{}`)", unexp, exp)) + fn invalid_value(unexpected: Unexpected<'_>, exp: &dyn Expected) -> Self { + Error::InvalidValue(format!("Invalid Value: {unexpected} (expected: `{exp}`)")) } fn invalid_length(len: usize, exp: &dyn Expected) -> Self { - Error::InvalidLength(format!("Invalid Length: {} (expected: {})", len, exp)) + Error::InvalidLength(format!("Invalid Length: {len} (expected: {exp})")) } fn unknown_variant(field: &str, expected: &'static [&'static str]) -> Self { Error::UnknownVariant(format!( - "Unknown Variant: `{}` (expected one of: {:?})", - field, expected + "Unknown Variant: `{field}` (expected one of: {expected:?})" )) } fn unknown_field(field: &str, expected: &'static [&'static str]) -> Self { Error::UnknownField(format!( - "Unknown Field: `{}` (expected one of: {:?})", - field, expected + "Unknown Field: `{field}` (expected one of: {expected:?})" )) } fn missing_field(field: &'static str) -> Self { - Error::MissingField(format!("Missing Field: `{}`", field)) + Error::MissingField(format!("Missing Field: `{field}`")) } fn duplicate_field(field: &'static str) -> Self { - Error::DuplicateField(format!("Duplicat Field: `{}`", field)) + Error::DuplicateField(format!("Duplicate Field: `{field}`")) } } @@ -106,7 +104,7 @@ impl StdError for Error { } impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let message = match *self { Error::IoError(ref error) => return error.fmt(f), Error::InvalidType(ref s) => s, diff --git a/src/ser.rs b/src/ser.rs index 663852b..ad99670 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -90,7 +90,7 @@ pub struct SerializeMap<'a> { } impl<'a> SerializeMap<'a> { - pub fn new(ser: &'a mut Serializer, len: usize) -> SerializeMap { + pub fn new(ser: &'a mut Serializer, len: usize) -> SerializeMap<'_> { SerializeMap { ser, entries: Vec::with_capacity(len), diff --git a/src/ser/string.rs b/src/ser/string.rs index 9d5fa46..72eca39 100644 --- a/src/ser/string.rs +++ b/src/ser/string.rs @@ -8,12 +8,12 @@ use std::str; struct Expected; impl de::Expected for Expected { - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { write!(formatter, "a string or bytes") } } -fn unexpected(unexp: de::Unexpected) -> Result { +fn unexpected(unexp: de::Unexpected<'_>) -> Result { Err(de::Error::invalid_type(unexp, &Expected)) } diff --git a/src/value.rs b/src/value.rs index ae5024c..8ee5773 100644 --- a/src/value.rs +++ b/src/value.rs @@ -54,7 +54,7 @@ struct ValueVisitor; impl<'de> de::Visitor<'de> for ValueVisitor { type Value = Value; - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter.write_str("any valid BEncode value") } diff --git a/tests/tests.rs b/tests/tests.rs index cb38b2e..4b04c90 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,5 +1,3 @@ -extern crate torrust_serde_bencode; - use serde::de::DeserializeOwned; use serde::Serialize; use serde_derive::{Deserialize, Serialize}; @@ -517,5 +515,5 @@ fn ser_de_flattened_enum() { #[test] fn deserialize_too_long_byte_string() { - let _: Result = from_str("123456789123:1"); + let _unused: Result = from_str("123456789123:1"); }