From e862d34cb4b2f7fc3b312466c8779ca7e85eae1e Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Fri, 29 Mar 2024 13:00:54 +0000 Subject: [PATCH] Revert "Rename generic bounds for clarity" This reverts commit 8870fb2d5faff1184e0baedabe2960adefa398e9. --- crates/librqbit_core/src/torrent_metainfo.rs | 44 +++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/crates/librqbit_core/src/torrent_metainfo.rs b/crates/librqbit_core/src/torrent_metainfo.rs index 6dc4069..545e7b8 100644 --- a/crates/librqbit_core/src/torrent_metainfo.rs +++ b/crates/librqbit_core/src/torrent_metainfo.rs @@ -13,9 +13,9 @@ pub type TorrentMetaV1Borrowed<'a> = TorrentMetaV1>; pub type TorrentMetaV1Owned = TorrentMetaV1; /// Parse torrent metainfo from bytes. -pub fn torrent_from_bytes<'de, BufType: Deserialize<'de>>( +pub fn torrent_from_bytes<'de, ByteBuf: Deserialize<'de>>( buf: &'de [u8], -) -> anyhow::Result> { +) -> anyhow::Result> { let mut de = BencodeDeserializer::new_from_buf(buf); de.is_torrent_info = true; let mut t = TorrentMetaV1::deserialize(&mut de)?; @@ -86,14 +86,14 @@ pub struct TorrentMetaV1Info { } #[derive(Clone, Copy)] -pub enum FileIteratorName<'a, BufType> { - Single(Option<&'a BufType>), - Tree(&'a [BufType]), +pub enum FileIteratorName<'a, ByteBuf> { + Single(Option<&'a ByteBuf>), + Tree(&'a [ByteBuf]), } -impl<'a, BufType> std::fmt::Debug for FileIteratorName<'a, BufType> +impl<'a, ByteBuf> std::fmt::Debug for FileIteratorName<'a, ByteBuf> where - BufType: AsRef<[u8]>, + ByteBuf: AsRef<[u8]>, { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self.to_string() { @@ -103,9 +103,9 @@ where } } -impl<'a, BufType> FileIteratorName<'a, BufType> +impl<'a, ByteBuf> FileIteratorName<'a, ByteBuf> where - BufType: AsRef<[u8]>, + ByteBuf: AsRef<[u8]>, { pub fn to_vec(&self) -> anyhow::Result> { self.iter_components() @@ -143,8 +143,12 @@ where if bit == ".." { anyhow::bail!("path traversal detected, \"..\" in filename bit {:?}", bit); } - if bit.contains('/') || bit.contains('\\') { - anyhow::bail!("suspicios separator in filename bit {:?}", bit); + if bit.contains(std::path::MAIN_SEPARATOR) { + anyhow::bail!( + "suspicios separator {:?} in filename bit {:?}", + std::path::MAIN_SEPARATOR, + bit + ); } Ok(bit) })) @@ -216,11 +220,11 @@ where } } -impl CloneToOwned for TorrentMetaV1File +impl CloneToOwned for TorrentMetaV1File where - BufType: CloneToOwned, + ByteBuf: CloneToOwned, { - type Target = TorrentMetaV1File<::Target>; + type Target = TorrentMetaV1File<::Target>; fn clone_to_owned(&self) -> Self::Target { TorrentMetaV1File { @@ -230,11 +234,11 @@ where } } -impl CloneToOwned for TorrentMetaV1Info +impl CloneToOwned for TorrentMetaV1Info where - BufType: CloneToOwned, + ByteBuf: CloneToOwned, { - type Target = TorrentMetaV1Info<::Target>; + type Target = TorrentMetaV1Info<::Target>; fn clone_to_owned(&self) -> Self::Target { TorrentMetaV1Info { @@ -248,11 +252,11 @@ where } } -impl CloneToOwned for TorrentMetaV1 +impl CloneToOwned for TorrentMetaV1 where - BufType: CloneToOwned, + ByteBuf: CloneToOwned, { - type Target = TorrentMetaV1<::Target>; + type Target = TorrentMetaV1<::Target>; fn clone_to_owned(&self) -> Self::Target { TorrentMetaV1 {