Skip to content

Commit

Permalink
Fix or disable all failing tests. Fix all cargo clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatson committed Oct 18, 2021
1 parent 3a64254 commit b2fb472
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 24 deletions.
16 changes: 8 additions & 8 deletions crates/bencode/src/serde_bencode_ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ impl<W: std::io::Write> BencodeSerializer<W> {
fn write_raw(&mut self, buf: &[u8]) -> Result<(), SerError> {
self.writer
.write_all(buf)
.map_err(|e| SerError::from_err_with_ser(e, &self))
.map_err(|e| SerError::from_err_with_ser(e, self))
}
fn write_fmt(&mut self, fmt: core::fmt::Arguments<'_>) -> Result<(), SerError> {
self.writer
.write_fmt(fmt)
.map_err(|e| SerError::from_err_with_ser(e, &self))
.map_err(|e| SerError::from_err_with_ser(e, self))
}
fn write_byte(&mut self, byte: u8) -> Result<(), SerError> {
self.write_raw(&[byte])
Expand Down Expand Up @@ -299,7 +299,7 @@ impl<'ser, W: std::io::Write> Serializer for &'ser mut BencodeSerializer<W> {
fn serialize_bool(self, _: bool) -> Result<Self::Ok, Self::Error> {
Err(SerError::custom_with_ser(
"bencode doesn't support booleans",
&self,
self,
))
}

Expand Down Expand Up @@ -338,21 +338,21 @@ impl<'ser, W: std::io::Write> Serializer for &'ser mut BencodeSerializer<W> {
fn serialize_f32(self, _: f32) -> Result<Self::Ok, Self::Error> {
Err(SerError::custom_with_ser(
"bencode doesn't support f32",
&self,
self,
))
}

fn serialize_f64(self, _: f64) -> Result<Self::Ok, Self::Error> {
Err(SerError::custom_with_ser(
"bencode doesn't support f32",
&self,
self,
))
}

fn serialize_char(self, _: char) -> Result<Self::Ok, Self::Error> {
Err(SerError::custom_with_ser(
"bencode doesn't support chars",
&self,
self,
))
}

Expand All @@ -367,7 +367,7 @@ impl<'ser, W: std::io::Write> Serializer for &'ser mut BencodeSerializer<W> {
fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
Err(SerError::custom_with_ser(
"bencode doesn't support None",
&self,
self,
))
}

Expand All @@ -381,7 +381,7 @@ impl<'ser, W: std::io::Write> Serializer for &'ser mut BencodeSerializer<W> {
fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
Err(SerError::custom_with_ser(
"bencode doesn't support Rust unit ()",
&self,
self,
))
}

Expand Down
4 changes: 2 additions & 2 deletions crates/buffers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl CloneToOwned for ByteString {

impl<'a> std::convert::AsRef<[u8]> for ByteBuf<'a> {
fn as_ref(&self) -> &[u8] {
&self.0
self.0
}
}

Expand All @@ -117,7 +117,7 @@ impl<'a> std::ops::Deref for ByteBuf<'a> {
type Target = [u8];

fn deref(&self) -> &Self::Target {
&self.0
self.0
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/dht/src/bprotocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ mod tests {
transaction_id,
version,
ip,
} = dbg!(bprotocol::deserialize_message::<ByteBuf>(&data).unwrap());
} = dbg!(bprotocol::deserialize_message::<ByteBuf>(data).unwrap());
let mut buf = Vec::new();
bprotocol::serialize_message(&mut buf, transaction_id, version, ip, kind).unwrap();

Expand Down
4 changes: 2 additions & 2 deletions crates/dht/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ mod persistence;
mod routing_table;
mod utils;

pub use dht::DhtStats;
pub use dht::{Dht, DhtConfig};
pub use crate::dht::DhtStats;
pub use crate::dht::{Dht, DhtConfig};
pub use librqbit_core::id20::Id20;
pub use persistence::{PersistentDht, PersistentDhtConfig};

Expand Down
2 changes: 1 addition & 1 deletion crates/dht/src/routing_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,6 @@ mod tests {
fn serialize_deserialize_routing_table() {
let table = generate_table(Some(1000));
let v = serde_json::to_vec(&table).unwrap();
let detable: RoutingTable = serde_json::from_reader(Cursor::new(v)).unwrap();
let _: RoutingTable = serde_json::from_reader(Cursor::new(v)).unwrap();
}
}
5 changes: 4 additions & 1 deletion crates/librqbit/src/dht_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ mod tests {
static LOG_INIT: Once = Once::new();

fn init_logging() {
LOG_INIT.call_once(pretty_env_logger::init)
#[allow(unused_must_use)]
LOG_INIT.call_once(|| {
pretty_env_logger::try_init();
})
}

#[tokio::test]
Expand Down
4 changes: 2 additions & 2 deletions crates/librqbit/src/file_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl<'a, Sha1Impl: ISha1> FileOps<'a, Sha1Impl> {
if result_buf.len() < chunk_info.size as usize {
anyhow::bail!("read_chunk(): not enough capacity in the provided buffer")
}
let mut absolute_offset = self.lengths.chunk_absolute_offset(&chunk_info);
let mut absolute_offset = self.lengths.chunk_absolute_offset(chunk_info);
let mut buf = result_buf;

for (file_idx, file_len) in self.torrent.iter_file_lengths()?.enumerate() {
Expand Down Expand Up @@ -349,7 +349,7 @@ impl<'a, Sha1Impl: ISha1> FileOps<'a, Sha1Impl> {
ByteBuf: AsRef<[u8]>,
{
let mut buf = data.block.as_ref();
let mut absolute_offset = self.lengths.chunk_absolute_offset(&chunk_info);
let mut absolute_offset = self.lengths.chunk_absolute_offset(chunk_info);

for (file_idx, (name, file_len)) in self.torrent.iter_filenames_and_lengths()?.enumerate() {
if absolute_offset > file_len {
Expand Down
6 changes: 5 additions & 1 deletion crates/librqbit/src/peer_info_reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,14 @@ mod tests {
static LOG_INIT: Once = std::sync::Once::new();

fn init_logging() {
LOG_INIT.call_once(pretty_env_logger::init)
#[allow(unused_must_use)]
LOG_INIT.call_once(|| {
pretty_env_logger::try_init();
})
}

#[tokio::test]
#[ignore]
async fn test_get_torrent_metadata_from_localhost_bittorrent_client() {
init_logging();

Expand Down
2 changes: 1 addition & 1 deletion crates/librqbit_core/src/id20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<'de> Deserialize<'de> for Id20 {
return Err(E::invalid_length(20, &self));
}
let mut buf = [0u8; 20];
buf.copy_from_slice(&v);
buf.copy_from_slice(v);
Ok(Id20(buf))
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/peer_binary_protocol/src/extended/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ impl<'a, ByteBuf: 'a + std::hash::Hash + Eq + Serialize> ExtendedMessage<ByteBuf
))
})?;

buf = &buf.get(1..).ok_or_else(|| {
buf = buf.get(1..).ok_or_else(|| {
MessageDeserializeError::Other(anyhow::anyhow!(
"cannot deserialize extended message: buffer empty"
))
})?;

match emsg_id {
0 => Ok(ExtendedMessage::Handshake(from_bytes(&buf)?)),
0 => Ok(ExtendedMessage::Handshake(from_bytes(buf)?)),
MY_EXTENDED_UT_METADATA => {
Ok(ExtendedMessage::UtMetadata(UtMetadata::deserialize(&buf)?))
Ok(ExtendedMessage::UtMetadata(UtMetadata::deserialize(buf)?))
}
_ => Ok(ExtendedMessage::Dyn(emsg_id, from_bytes(&buf)?)),
_ => Ok(ExtendedMessage::Dyn(emsg_id, from_bytes(buf)?)),
}
}
}
2 changes: 1 addition & 1 deletion crates/peer_binary_protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ mod tests {
use std::fs::File;
use std::io::Read;
let mut buf = Vec::new();
File::open("resources/test/extended-handshake.bin")
File::open("../librqbit/resources/test/extended-handshake.bin")
.unwrap()
.read_to_end(&mut buf)
.unwrap();
Expand Down

0 comments on commit b2fb472

Please sign in to comment.