From cc452dd8c2c32fb8905966a6416a083a1bf2441b Mon Sep 17 00:00:00 2001 From: Artem Vorotnikov Date: Sat, 15 Oct 2022 17:27:30 +0400 Subject: [PATCH] Represent torrent status as enum --- Cargo.toml | 1 + src/types/mod.rs | 2 +- src/types/response.rs | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2df32a9..984bbc9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ reqwest = { version = "0.11.11", features = [ "rustls-tls", ], default-features = false } serde = { version = "1.0.144", features = ["derive"] } +serde_repr = "0.1" enum-iterator = "1.2.0" dotenvy = "0.15.5" diff --git a/src/types/mod.rs b/src/types/mod.rs index 3e3da76..6b32d5a 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -18,5 +18,5 @@ pub use self::request::{ pub(crate) use self::response::RpcResponseArgument; pub use self::response::{ BlocklistUpdate, FreeSpace, Nothing, PortTest, RpcResponse, SessionClose, SessionGet, - SessionStats, Torrent, TorrentAddedOrDuplicate, TorrentRenamePath, Torrents, + SessionStats, Torrent, TorrentAddedOrDuplicate, TorrentRenamePath, TorrentStatus, Torrents, }; diff --git a/src/types/response.rs b/src/types/response.rs index e3d3a51..c42ffd1 100644 --- a/src/types/response.rs +++ b/src/types/response.rs @@ -1,4 +1,6 @@ use serde::Deserialize; +use serde_repr::*; + #[derive(Deserialize, Debug)] pub struct RpcResponse { pub arguments: T, @@ -65,6 +67,18 @@ pub struct PortTest { } impl RpcResponseArgument for PortTest {} +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Serialize_repr, Deserialize_repr)] +#[repr(u8)] +pub enum TorrentStatus { + Stopped = 0, + QueuedToVerify = 1, + Verifying = 2, + QueuedToDownload = 3, + Downloading = 4, + QueuedToSeed = 5, + Seeding = 6, +} + #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct Torrent { @@ -95,7 +109,7 @@ pub struct Torrent { pub seconds_seeding: Option, pub seed_ratio_limit: Option, pub size_when_done: Option, - pub status: Option, + pub status: Option, pub torrent_file: Option, pub total_size: Option, pub trackers: Option>,