diff --git a/crates/bencode/src/serde_bencode_ser.rs b/crates/bencode/src/serde_bencode_ser.rs index 60e9b19..4f6bd0b 100644 --- a/crates/bencode/src/serde_bencode_ser.rs +++ b/crates/bencode/src/serde_bencode_ser.rs @@ -73,12 +73,12 @@ impl BencodeSerializer { 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]) @@ -299,7 +299,7 @@ impl<'ser, W: std::io::Write> Serializer for &'ser mut BencodeSerializer { fn serialize_bool(self, _: bool) -> Result { Err(SerError::custom_with_ser( "bencode doesn't support booleans", - &self, + self, )) } @@ -338,21 +338,21 @@ impl<'ser, W: std::io::Write> Serializer for &'ser mut BencodeSerializer { fn serialize_f32(self, _: f32) -> Result { Err(SerError::custom_with_ser( "bencode doesn't support f32", - &self, + self, )) } fn serialize_f64(self, _: f64) -> Result { Err(SerError::custom_with_ser( "bencode doesn't support f32", - &self, + self, )) } fn serialize_char(self, _: char) -> Result { Err(SerError::custom_with_ser( "bencode doesn't support chars", - &self, + self, )) } @@ -367,7 +367,7 @@ impl<'ser, W: std::io::Write> Serializer for &'ser mut BencodeSerializer { fn serialize_none(self) -> Result { Err(SerError::custom_with_ser( "bencode doesn't support None", - &self, + self, )) } @@ -381,7 +381,7 @@ impl<'ser, W: std::io::Write> Serializer for &'ser mut BencodeSerializer { fn serialize_unit(self) -> Result { Err(SerError::custom_with_ser( "bencode doesn't support Rust unit ()", - &self, + self, )) } diff --git a/crates/buffers/src/lib.rs b/crates/buffers/src/lib.rs index 007f8fa..fef2a09 100644 --- a/crates/buffers/src/lib.rs +++ b/crates/buffers/src/lib.rs @@ -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 } } @@ -117,7 +117,7 @@ impl<'a> std::ops::Deref for ByteBuf<'a> { type Target = [u8]; fn deref(&self) -> &Self::Target { - &self.0 + self.0 } } diff --git a/crates/dht/src/bprotocol.rs b/crates/dht/src/bprotocol.rs index 2c90aab..050a6a0 100644 --- a/crates/dht/src/bprotocol.rs +++ b/crates/dht/src/bprotocol.rs @@ -539,7 +539,7 @@ mod tests { transaction_id, version, ip, - } = dbg!(bprotocol::deserialize_message::(&data).unwrap()); + } = dbg!(bprotocol::deserialize_message::(data).unwrap()); let mut buf = Vec::new(); bprotocol::serialize_message(&mut buf, transaction_id, version, ip, kind).unwrap(); diff --git a/crates/dht/src/lib.rs b/crates/dht/src/lib.rs index 7dba05c..9000fcc 100644 --- a/crates/dht/src/lib.rs +++ b/crates/dht/src/lib.rs @@ -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}; diff --git a/crates/dht/src/routing_table.rs b/crates/dht/src/routing_table.rs index 48cfaeb..89cd404 100644 --- a/crates/dht/src/routing_table.rs +++ b/crates/dht/src/routing_table.rs @@ -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(); } } diff --git a/crates/librqbit/src/dht_utils.rs b/crates/librqbit/src/dht_utils.rs index 7fe2897..a439442 100644 --- a/crates/librqbit/src/dht_utils.rs +++ b/crates/librqbit/src/dht_utils.rs @@ -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] diff --git a/crates/librqbit/src/file_ops.rs b/crates/librqbit/src/file_ops.rs index 9320fe8..a82b870 100644 --- a/crates/librqbit/src/file_ops.rs +++ b/crates/librqbit/src/file_ops.rs @@ -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() { @@ -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 { diff --git a/crates/librqbit/src/peer_info_reader/mod.rs b/crates/librqbit/src/peer_info_reader/mod.rs index 8a30cc1..071967e 100644 --- a/crates/librqbit/src/peer_info_reader/mod.rs +++ b/crates/librqbit/src/peer_info_reader/mod.rs @@ -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(); diff --git a/crates/librqbit_core/src/id20.rs b/crates/librqbit_core/src/id20.rs index 5833fc3..d7fadfa 100644 --- a/crates/librqbit_core/src/id20.rs +++ b/crates/librqbit_core/src/id20.rs @@ -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)) } } diff --git a/crates/peer_binary_protocol/src/extended/mod.rs b/crates/peer_binary_protocol/src/extended/mod.rs index 0a3569a..aaccbb6 100644 --- a/crates/peer_binary_protocol/src/extended/mod.rs +++ b/crates/peer_binary_protocol/src/extended/mod.rs @@ -79,18 +79,18 @@ impl<'a, ByteBuf: 'a + std::hash::Hash + Eq + Serialize> ExtendedMessage 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)?)), } } } diff --git a/crates/peer_binary_protocol/src/lib.rs b/crates/peer_binary_protocol/src/lib.rs index ff563fb..0c6f633 100644 --- a/crates/peer_binary_protocol/src/lib.rs +++ b/crates/peer_binary_protocol/src/lib.rs @@ -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();