Skip to content

Commit

Permalink
Rename generic bounds for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatson committed Mar 29, 2024
1 parent fa05fe8 commit c481f77
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions crates/librqbit_core/src/torrent_metainfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ pub type TorrentMetaV1Borrowed<'a> = TorrentMetaV1<ByteBuf<'a>>;
pub type TorrentMetaV1Owned = TorrentMetaV1<ByteBufOwned>;

/// Parse torrent metainfo from bytes.
pub fn torrent_from_bytes<'de, ByteBuf: Deserialize<'de>>(
pub fn torrent_from_bytes<'de, BufType: Deserialize<'de>>(
buf: &'de [u8],
) -> anyhow::Result<TorrentMetaV1<ByteBuf>> {
) -> anyhow::Result<TorrentMetaV1<BufType>> {
let mut de = BencodeDeserializer::new_from_buf(buf);
de.is_torrent_info = true;
let mut t = TorrentMetaV1::deserialize(&mut de)?;
Expand Down Expand Up @@ -86,14 +86,14 @@ pub struct TorrentMetaV1Info<BufType> {
}

#[derive(Clone, Copy)]
pub enum FileIteratorName<'a, ByteBuf> {
Single(Option<&'a ByteBuf>),
Tree(&'a [ByteBuf]),
pub enum FileIteratorName<'a, BufType> {
Single(Option<&'a BufType>),
Tree(&'a [BufType]),
}

impl<'a, ByteBuf> std::fmt::Debug for FileIteratorName<'a, ByteBuf>
impl<'a, BufType> std::fmt::Debug for FileIteratorName<'a, BufType>
where
ByteBuf: AsRef<[u8]>,
BufType: AsRef<[u8]>,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.to_string() {
Expand All @@ -103,9 +103,9 @@ where
}
}

impl<'a, ByteBuf> FileIteratorName<'a, ByteBuf>
impl<'a, BufType> FileIteratorName<'a, BufType>
where
ByteBuf: AsRef<[u8]>,
BufType: AsRef<[u8]>,
{
pub fn to_vec(&self) -> anyhow::Result<Vec<String>> {
self.iter_components()
Expand Down Expand Up @@ -143,12 +143,8 @@ where
if bit == ".." {
anyhow::bail!("path traversal detected, \"..\" in filename bit {:?}", bit);
}
if bit.contains(std::path::MAIN_SEPARATOR) {
anyhow::bail!(
"suspicios separator {:?} in filename bit {:?}",
std::path::MAIN_SEPARATOR,
bit
);
if bit.contains('/') || bit.contains('\\') {
anyhow::bail!("suspicios separator in filename bit {:?}", bit);
}
Ok(bit)
}))
Expand Down Expand Up @@ -220,11 +216,11 @@ where
}
}

impl<ByteBuf> CloneToOwned for TorrentMetaV1File<ByteBuf>
impl<BufType> CloneToOwned for TorrentMetaV1File<BufType>
where
ByteBuf: CloneToOwned,
BufType: CloneToOwned,
{
type Target = TorrentMetaV1File<<ByteBuf as CloneToOwned>::Target>;
type Target = TorrentMetaV1File<<BufType as CloneToOwned>::Target>;

fn clone_to_owned(&self) -> Self::Target {
TorrentMetaV1File {
Expand All @@ -234,11 +230,11 @@ where
}
}

impl<ByteBuf> CloneToOwned for TorrentMetaV1Info<ByteBuf>
impl<BufType> CloneToOwned for TorrentMetaV1Info<BufType>
where
ByteBuf: CloneToOwned,
BufType: CloneToOwned,
{
type Target = TorrentMetaV1Info<<ByteBuf as CloneToOwned>::Target>;
type Target = TorrentMetaV1Info<<BufType as CloneToOwned>::Target>;

fn clone_to_owned(&self) -> Self::Target {
TorrentMetaV1Info {
Expand All @@ -252,11 +248,11 @@ where
}
}

impl<ByteBuf> CloneToOwned for TorrentMetaV1<ByteBuf>
impl<BufType> CloneToOwned for TorrentMetaV1<BufType>
where
ByteBuf: CloneToOwned,
BufType: CloneToOwned,
{
type Target = TorrentMetaV1<<ByteBuf as CloneToOwned>::Target>;
type Target = TorrentMetaV1<<BufType as CloneToOwned>::Target>;

fn clone_to_owned(&self) -> Self::Target {
TorrentMetaV1 {
Expand Down

0 comments on commit c481f77

Please sign in to comment.