feat: helper

This commit is contained in:
George Miao 2022-11-05 14:56:42 -04:00 committed by Aleksandr
parent f61a41be8a
commit ed924a5a51

View File

@ -1,6 +1,8 @@
use serde::Deserialize;
use serde_repr::*;
use crate::types::Id;
#[derive(Deserialize, Debug)]
pub struct RpcResponse<T: RpcResponseArgument> {
pub arguments: T,
@ -123,6 +125,16 @@ pub struct Torrent {
pub file_stats: Option<Vec<FileStat>>,
}
impl Torrent {
/// Get either the ID or the hash string if exist, which are both unique and
/// can be pass to the API.
pub fn id(&self) -> Option<Id> {
self.id
.map(Id::Id)
.or_else(|| self.hash_string.clone().map(Id::Hash))
}
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Stats {