aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorboasting-squirrel <boasting.squirrel@gmail.com>2019-04-07 10:21:58 +0000
committerboasting-squirrel <boasting.squirrel@gmail.com>2019-04-07 10:21:58 +0000
commitc24986640589df2aa5b2f7360cc8bea71ed49fbb (patch)
treef95d72cf6b1015ddbc8a7313bf256663ebc7e74f /src
parentFixed upload bug + refactored @ else in templates (diff)
downloadminiserve-c24986640589df2aa5b2f7360cc8bea71ed49fbb.tar.gz
miniserve-c24986640589df2aa5b2f7360cc8bea71ed49fbb.zip
Use strum_macros::EnumIter instead of manually listing Enum variants
Diffstat (limited to 'src')
-rw-r--r--src/archive.rs8
-rw-r--r--src/renderer.rs5
-rw-r--r--src/themes.rs13
3 files changed, 7 insertions, 19 deletions
diff --git a/src/archive.rs b/src/archive.rs
index b1119f0..f588d56 100644
--- a/src/archive.rs
+++ b/src/archive.rs
@@ -6,11 +6,12 @@ use serde::Deserialize;
use std::io;
use std::path::PathBuf;
use tar::Builder;
+use strum_macros::EnumIter;
use crate::errors;
/// Available compression methods
-#[derive(Debug, Deserialize, Clone)]
+#[derive(Debug, Deserialize, Clone, EnumIter)]
pub enum CompressionMethod {
/// TAR GZ
#[serde(alias = "targz")]
@@ -25,11 +26,6 @@ impl CompressionMethod {
.to_string()
}
- /// Lists compression methods
- pub fn get_compression_methods() -> Vec<Self> {
- vec![CompressionMethod::TarGz]
- }
-
pub fn extension(&self) -> String {
match &self {
CompressionMethod::TarGz => "tar.gz",
diff --git a/src/renderer.rs b/src/renderer.rs
index 2d6fd88..1371ab6 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -2,6 +2,7 @@ use chrono::{DateTime, Duration, Utc};
use chrono_humanize::{Accuracy, HumanTime, Tense};
use maud::{html, Markup, PreEscaped, DOCTYPE};
use std::time::SystemTime;
+use strum::IntoEnumIterator;
use crate::archive;
use crate::listing;
@@ -36,7 +37,7 @@ pub fn page(
h1.title { (page_title) }
div.toolbar {
div.download {
- @for compression_method in archive::CompressionMethod::get_compression_methods() {
+ @for compression_method in archive::CompressionMethod::iter() {
(archive_button(compression_method))
}
}
@@ -98,7 +99,7 @@ fn color_scheme_selector(
"Change theme..."
}
ul {
- @for color_scheme in themes::ColorScheme::get_color_schemes() {
+ @for color_scheme in themes::ColorScheme::iter() {
@if active_color_scheme.get_name() == color_scheme.get_name() {
li.active {
(color_scheme_link(&sort_method, &sort_order, &color_scheme))
diff --git a/src/themes.rs b/src/themes.rs
index dca656d..8635c8f 100644
--- a/src/themes.rs
+++ b/src/themes.rs
@@ -1,8 +1,9 @@
use serde::Deserialize;
use structopt::clap::{_clap_count_exprs, arg_enum};
+use strum_macros::EnumIter;
arg_enum! {
- #[derive(Debug, Deserialize, Clone)]
+ #[derive(Debug, Deserialize, Clone, EnumIter)]
#[serde(rename_all = "lowercase")]
pub enum ColorScheme {
Archlinux,
@@ -45,16 +46,6 @@ impl ColorScheme {
.to_string()
}
- /// Lists available color schemes
- pub fn get_color_schemes() -> Vec<Self> {
- vec![
- ColorScheme::Archlinux,
- ColorScheme::Zenburn,
- ColorScheme::Monokai,
- ColorScheme::Squirrel,
- ]
- }
-
/// Retrieves the color palette associated to a color scheme
pub fn get_theme(self) -> Theme {
match self {