Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move from boxing to impl trait #2

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/trackers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ pub trait Torrent: std::fmt::Debug {
}

pub trait Tracker {
fn parse_message(msg: &str) -> Option<Box<dyn Torrent>>;
type Torrent: Torrent;

fn parse_message(msg: &str) -> Option<Self::Torrent>;
}
8 changes: 5 additions & 3 deletions src/trackers/torrentleech.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ impl super::Torrent for TorrentleechTorrent {


impl super::Tracker for TorrentleechTracker {
fn parse_message(msg: &str) -> Option<Box<dyn super::Torrent>> {
type Torrent = TorrentleechTorrent;

fn parse_message(msg: &str) -> Option<Self::Torrent> {
// println!("Going ot par")
let name_start_index = msg.find("Name:'")?;
let name_end_index = msg.find("' uploaded by '")?;
Expand All @@ -32,11 +34,11 @@ impl super::Tracker for TorrentleechTracker {
}
};

Some(Box::new(TorrentleechTorrent{
Some(TorrentleechTorrent{
name: msg[name_start_index+6..name_end_index].to_owned(),
uploader: msg[name_end_index+15..uploader_end_index].to_owned(),
url: msg[uploader_end_index+lenn..].to_owned(),
freeleech: freeleech,
}))
})
}
}