updated enum iterator

This commit is contained in:
Aleksandr Bochev 2022-10-02 17:29:09 +02:00 committed by Aleksandr
parent c35410dc7b
commit f39a6eb1d4
2 changed files with 5 additions and 11 deletions

View File

@ -17,7 +17,7 @@ reqwest = { version = "0.11.11", features = [
"rustls-tls", "rustls-tls",
], default-features = false } ], default-features = false }
serde = { version = "1.0.144", features = ["derive"] } serde = { version = "1.0.144", features = ["derive"] }
enum-iterator = "0.8.1" enum-iterator = "1.2.0"
dotenvy = "0.15.5" dotenvy = "0.15.5"
log = "0.4.17" log = "0.4.17"

View File

@ -1,4 +1,4 @@
use enum_iterator::IntoEnumIterator; use enum_iterator::{all, Sequence};
use serde::Serialize; use serde::Serialize;
#[derive(Serialize, Debug)] #[derive(Serialize, Debug)]
@ -53,7 +53,7 @@ impl RpcRequest {
pub fn torrent_get(fields: Option<Vec<TorrentGetField>>, ids: Option<Vec<Id>>) -> RpcRequest { pub fn torrent_get(fields: Option<Vec<TorrentGetField>>, ids: Option<Vec<Id>>) -> RpcRequest {
let string_fields = fields let string_fields = fields
.unwrap_or(TorrentGetField::all()) .unwrap_or(all::<TorrentGetField>().collect())
.iter() .iter()
.map(TorrentGetField::to_str) .map(TorrentGetField::to_str)
.collect(); .collect();
@ -155,9 +155,7 @@ pub struct TorrentGetArgs {
impl Default for TorrentGetArgs { impl Default for TorrentGetArgs {
fn default() -> Self { fn default() -> Self {
let all_fields = TorrentGetField::into_enum_iter() let all_fields = all::<TorrentGetField>().map(|it| it.to_str()).collect();
.map(|it| it.to_str())
.collect();
TorrentGetArgs { TorrentGetArgs {
fields: Some(all_fields), fields: Some(all_fields),
ids: None, ids: None,
@ -239,7 +237,7 @@ pub struct TorrentAddArgs {
pub labels: Option<Vec<String>>, pub labels: Option<Vec<String>>,
} }
#[derive(Clone, Copy, IntoEnumIterator)] #[derive(Clone, Copy, Sequence)]
pub enum TorrentGetField { pub enum TorrentGetField {
ActivityDate, ActivityDate,
AddedDate, AddedDate,
@ -283,10 +281,6 @@ pub enum TorrentGetField {
} }
impl TorrentGetField { impl TorrentGetField {
pub fn all() -> Vec<TorrentGetField> {
TorrentGetField::into_enum_iter().collect()
}
#[must_use] #[must_use]
pub fn to_str(&self) -> String { pub fn to_str(&self) -> String {
match self { match self {