diff --git a/crates/librqbit/src/torrent_manager.rs b/crates/librqbit/src/torrent_manager.rs index c54ae15..5c4f1b0 100644 --- a/crates/librqbit/src/torrent_manager.rs +++ b/crates/librqbit/src/torrent_manager.rs @@ -2,7 +2,6 @@ use std::{ collections::HashSet, fs::{File, OpenOptions}, net::SocketAddr, - ops::Deref, path::{Path, PathBuf}, sync::Arc, time::{Duration, Instant}, @@ -139,7 +138,7 @@ struct TorrentManager { force_tracker_interval: Option, } -fn make_lengths>( +fn make_lengths>( torrent: &TorrentMetaV1Info, ) -> anyhow::Result { let total_length = torrent.iter_file_lengths().sum(); diff --git a/crates/librqbit_core/src/torrent_metainfo.rs b/crates/librqbit_core/src/torrent_metainfo.rs index f094ae2..b11be90 100644 --- a/crates/librqbit_core/src/torrent_metainfo.rs +++ b/crates/librqbit_core/src/torrent_metainfo.rs @@ -1,4 +1,4 @@ -use std::{fmt::Write, ops::Deref, path::PathBuf}; +use std::{fmt::Write, path::PathBuf}; use bencode::BencodeDeserializer; use buffers::{ByteBuf, ByteString}; @@ -8,7 +8,7 @@ use serde::Deserialize; pub type TorrentMetaV1Borrowed<'a> = TorrentMetaV1>; pub type TorrentMetaV1Owned = TorrentMetaV1; -pub fn torrent_from_bytes<'de, ByteBuf: Clone + Deserialize<'de>>( +pub fn torrent_from_bytes<'de, ByteBuf: Deserialize<'de>>( buf: &'de [u8], ) -> anyhow::Result> { let mut de = BencodeDeserializer::new_from_buf(buf); @@ -19,7 +19,7 @@ pub fn torrent_from_bytes<'de, ByteBuf: Clone + Deserialize<'de>>( } #[derive(Deserialize, Debug, Clone)] -pub struct TorrentMetaV1 { +pub struct TorrentMetaV1 { pub announce: BufType, #[serde(rename = "announce-list")] pub announce_list: Vec>, @@ -38,14 +38,14 @@ pub struct TorrentMetaV1 { pub info_hash: [u8; 20], } -impl TorrentMetaV1 { +impl TorrentMetaV1 { pub fn iter_announce(&self) -> impl Iterator { std::iter::once(&self.announce).chain(self.announce_list.iter().flatten()) } } #[derive(Deserialize, Debug, Clone)] -pub struct TorrentMetaV1Info { +pub struct TorrentMetaV1Info { pub name: Option, pub pieces: BufType, #[serde(rename = "piece length")] @@ -116,17 +116,17 @@ impl<'a, ByteBuf> FileIteratorName<'a, ByteBuf> { } } -impl> TorrentMetaV1Info { +impl> TorrentMetaV1Info { pub fn get_hash(&self, piece: u32) -> Option<&[u8]> { let start = piece as usize * 20; let end = start + 20; - let expected_hash = self.pieces.deref().get(start..end)?; + let expected_hash = self.pieces.as_ref().get(start..end)?; Some(expected_hash) } pub fn compare_hash(&self, piece: u32, hash: [u8; 20]) -> Option { let start = piece as usize * 20; let end = start + 20; - let expected_hash = self.pieces.deref().get(start..end)?; + let expected_hash = self.pieces.as_ref().get(start..end)?; Some(expected_hash == hash) } pub fn iter_filenames_and_lengths( @@ -158,14 +158,14 @@ impl> TorrentMetaV1Info { } #[derive(Deserialize, Debug, Clone)] -pub struct TorrentMetaV1File { +pub struct TorrentMetaV1File { pub length: u64, pub path: Vec, } impl TorrentMetaV1File where - BufType: Clone + AsRef<[u8]>, + BufType: AsRef<[u8]>, { pub fn full_path(&self, parent: &mut PathBuf) -> anyhow::Result<()> { for p in self.path.iter() { @@ -178,8 +178,7 @@ where impl CloneToOwned for TorrentMetaV1File where - ByteBuf: CloneToOwned + Clone, - ::Target: Clone, + ByteBuf: CloneToOwned, { type Target = TorrentMetaV1File<::Target>; @@ -193,8 +192,7 @@ where impl CloneToOwned for TorrentMetaV1Info where - ByteBuf: CloneToOwned + Clone, - ::Target: Clone, + ByteBuf: CloneToOwned, { type Target = TorrentMetaV1Info<::Target>; @@ -212,8 +210,7 @@ where impl CloneToOwned for TorrentMetaV1 where - ByteBuf: CloneToOwned + Clone, - ::Target: Clone, + ByteBuf: CloneToOwned, { type Target = TorrentMetaV1<::Target>; diff --git a/crates/rqbit/src/main.rs b/crates/rqbit/src/main.rs index 8b4be30..f9b640c 100644 --- a/crates/rqbit/src/main.rs +++ b/crates/rqbit/src/main.rs @@ -91,7 +91,7 @@ struct Opts { single_thread_runtime: bool, } -fn compute_only_files + AsRef<[u8]>>( +fn compute_only_files>( torrent: &TorrentMetaV1Info, filename_re: &str, ) -> anyhow::Result> {