Skip to content

Commit

Permalink
fix: cargo build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Sep 25, 2023
1 parent caf8cf5 commit cdd4200
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 23 deletions.
1 change: 1 addition & 0 deletions cSpell.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"words": [
"bencoded",
"httpseeds",
"Serde"
],
"enableFiletypes": [
Expand Down
4 changes: 1 addition & 3 deletions examples/parse_torrent.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -19,6 +16,7 @@ struct File {
md5sum: Option<String>,
}

#[allow(dead_code)]
#[derive(Debug, Deserialize)]
struct Info {
pub name: String,
Expand Down
2 changes: 1 addition & 1 deletion src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R>,
len: Option<usize>,
}
Expand Down
22 changes: 10 additions & 12 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}`"))
}
}

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions src/ser/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(unexp: de::Unexpected) -> Result<T> {
fn unexpected<T>(unexp: de::Unexpected<'_>) -> Result<T> {
Err(de::Error::invalid_type(unexp, &Expected))
}

Expand Down
2 changes: 1 addition & 1 deletion src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
4 changes: 1 addition & 3 deletions tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate torrust_serde_bencode;

use serde::de::DeserializeOwned;
use serde::Serialize;
use serde_derive::{Deserialize, Serialize};
Expand Down Expand Up @@ -517,5 +515,5 @@ fn ser_de_flattened_enum() {

#[test]
fn deserialize_too_long_byte_string() {
let _: Result<Value> = from_str("123456789123:1");
let _unused: Result<Value> = from_str("123456789123:1");
}

0 comments on commit cdd4200

Please sign in to comment.