diff --git a/src/types/mod.rs b/src/types/mod.rs index 98b71d7..a7f47b3 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -11,7 +11,7 @@ pub struct BasicAuth { pub(crate) use self::request::RpcRequest; pub use self::request::{ - ArgumentFields, Id, SessionSetArgs, TorrentAction, TorrentAddArgs, TorrentGetField, + ArgumentFields, Id, Priority, SessionSetArgs, TorrentAction, TorrentAddArgs, TorrentGetField, TorrentRenamePathArgs, TorrentSetArgs, TrackerList, }; diff --git a/src/types/request.rs b/src/types/request.rs index 329aaa4..eab4ba8 100644 --- a/src/types/request.rs +++ b/src/types/request.rs @@ -1,5 +1,6 @@ use enum_iterator::{all, Sequence}; use serde::Serialize; +use serde_repr::Deserialize_repr; #[derive(Serialize, Debug)] pub struct RpcRequest { @@ -420,6 +421,14 @@ pub enum Id { Hash(String), } +#[derive(Serialize, Deserialize_repr, Debug, Clone, PartialEq, Eq)] +#[repr(i8)] +pub enum Priority { + Low = -1, + Normal = 0, + High = 1, +} + #[derive(Serialize, Debug, Clone, Default)] pub struct TorrentAddArgs { #[serde(skip_serializing_if = "Option::is_none")] @@ -440,7 +449,7 @@ pub struct TorrentAddArgs { #[serde(skip_serializing_if = "Option::is_none", rename = "peer-limit")] pub peer_limit: Option, #[serde(skip_serializing_if = "Option::is_none", rename = "bandwidthPriority")] - pub bandwidth_priority: Option, + pub bandwidth_priority: Option, /// list of indices of files to be downloaded /// to ignore some files, put their indices in files_unwanted, otherwise /// they will still be downloaded @@ -598,7 +607,7 @@ impl Serialize for TrackerList { #[serde(rename_all = "camelCase")] pub struct TorrentSetArgs { #[serde(skip_serializing_if = "Option::is_none")] - pub bandwidth_priority: Option, + pub bandwidth_priority: Option, #[serde(skip_serializing_if = "Option::is_none")] pub download_limit: Option, #[serde(skip_serializing_if = "Option::is_none")] diff --git a/src/types/response.rs b/src/types/response.rs index 36a9c9d..15a9afb 100644 --- a/src/types/response.rs +++ b/src/types/response.rs @@ -1,6 +1,7 @@ use serde::Deserialize; use serde_repr::*; +use crate::types::request::Priority; use crate::types::Id; #[derive(Deserialize, Debug)] @@ -99,7 +100,7 @@ pub enum ErrorType { pub struct Torrent { pub activity_date: Option, pub added_date: Option, - pub bandwidth_priority: Option, + pub bandwidth_priority: Option, pub done_date: Option, pub download_dir: Option, pub edit_date: Option, @@ -134,8 +135,7 @@ pub struct Torrent { pub files: Option>, /// for each file in files, whether or not they will be downloaded (0 or 1) pub wanted: Option>, - /// for each file in files, their download priority (low:-1,normal:0,high:1) - pub priorities: Option>, + pub priorities: Option>, pub file_stats: Option>, #[serde(rename = "file-count")] pub file_count: Option, @@ -186,8 +186,7 @@ pub struct File { pub struct FileStat { pub bytes_completed: i64, pub wanted: bool, - /// low: -1, normal: 0, high: 1 - pub priority: i8, + pub priority: Priority, } #[derive(Deserialize, Debug)]