diff --git a/src/client.rs b/src/client.rs index 32cc4aa..741e5a9 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,20 +1,20 @@ use crate::{error::ClientError, TorrentInfo, TorrentTracker, TorrentUpload}; -pub struct ConnectionInfo { - pub url: String, - pub username: String, - pub password: String, +pub struct ConnectionInfo<'a> { + pub url: &'a str, + pub username: &'a str, + pub password: &'a str, } pub type ClientResult = Result; -pub struct QBittorrentClient { +pub struct QBittorrentClient<'a> { client: reqwest::Client, - connection_info: Option, + connection_info: Option>, auth_string: Option, } -impl QBittorrentClient { +impl<'a> QBittorrentClient<'a> { pub fn new() -> Self { Self { client: reqwest::Client::new(), @@ -24,7 +24,7 @@ impl QBittorrentClient { } /// Login to qBittorrent. This must be ran so that the client can make requests. - pub async fn login(&mut self, url: String, username: String, password: String) -> ClientResult<()> { + pub async fn login(&mut self, url: &'a str, username: &'a str, password: &'a str) -> ClientResult<()> { // Send response to get auth string let resp = self.client.post(format!("{}/api/v2/auth/login", url.clone())) .form(&[ @@ -185,7 +185,7 @@ impl QBittorrentClient { } /// Remove multiple torrents at once. `delete_files` applies to *all* torrents. - pub async fn remove_torrents(&self, torrents: Vec<&TorrentInfo>, delete_files: bool ) -> ClientResult<()> { + pub async fn remove_torrents(&self, torrents: Vec, delete_files: bool ) -> ClientResult<()> { if let (Some(auth_string), Some(conn)) = (self.auth_string.as_ref(), self.connection_info.as_ref()) { // Convert the hashes into a string concatenated with `|` let hashes = torrents.iter() diff --git a/src/torrent.rs b/src/torrent.rs index 09b99cd..55fa3b5 100644 --- a/src/torrent.rs +++ b/src/torrent.rs @@ -3,7 +3,7 @@ use serde_repr::*; use serde_with::{CommaSeparator}; /// A torrent's information from the qbittorrent client. -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Default, Serialize, Deserialize)] pub struct TorrentInfo { /// Time (Unix Epoch) when the torrent was added to the client pub added_on: u64, @@ -224,6 +224,12 @@ pub enum TorrentState { Unknown, } +impl Default for TorrentState { + fn default() -> Self { + TorrentState::Unknown + } +} + #[derive(Debug, Serialize, Deserialize)] pub struct TorrentTracker { /// Tracker URL @@ -254,7 +260,7 @@ pub struct TorrentTracker { pub message: String, } -#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)] +#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug, Clone)] #[repr(u8)] pub enum TrackerStatus { /// Tracker is disabled (used for DHT, PeX, and LSD)