aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorboasting-squirrel <boasting.squirrel@gmail.com>2019-02-19 19:21:13 +0000
committerboasting-squirrel <boasting.squirrel@gmail.com>2019-02-19 19:21:13 +0000
commit89f63763dab8f74ae5f5fb474296dbb1063d0d99 (patch)
tree330b50cd2eb923d4df29e3a3696affbef323b9ca
parentAdded missing ; in CSS (diff)
downloadminiserve-89f63763dab8f74ae5f5fb474296dbb1063d0d99.tar.gz
miniserve-89f63763dab8f74ae5f5fb474296dbb1063d0d99.zip
Improved code
Diffstat (limited to '')
-rw-r--r--src/listing.rs26
1 files changed, 10 insertions, 16 deletions
diff --git a/src/listing.rs b/src/listing.rs
index 0404005..9203f48 100644
--- a/src/listing.rs
+++ b/src/listing.rs
@@ -313,16 +313,15 @@ pub fn directory_listing<S>(
///
/// If no SystemTime was given, returns a tuple containing empty strings
fn convert_to_utc(src_time: Option<SystemTime>) -> (String, String) {
- match src_time {
- Some(time) => {
- let date_time = DateTime::<Utc>::from(time);
+ src_time
+ .map(|time| DateTime::<Utc>::from(time))
+ .map(|date_time| {
(
date_time.format("%e %b").to_string(),
date_time.format("%R").to_string(),
)
- }
- None => ("".to_string(), "".to_string()),
- }
+ })
+ .unwrap_or_default()
}
/// Converts a SystemTime to a string readable by a human,
@@ -331,14 +330,9 @@ fn convert_to_utc(src_time: Option<SystemTime>) -> (String, String) {
///
/// If no SystemTime was given, returns an empty string
fn humanize_duration(src_time: Option<SystemTime>) -> String {
- match src_time {
- Some(std_time) => match SystemTime::now().duration_since(std_time) {
- Ok(from_now) => match Duration::from_std(from_now) {
- Ok(duration) => HumanTime::from(duration).to_text_en(Accuracy::Rough, Tense::Past),
- Err(_) => "".to_string(),
- },
- Err(_) => "".to_string(),
- },
- None => "".to_string(),
- }
+ src_time
+ .and_then(|std_time| SystemTime::now().duration_since(std_time).ok())
+ .and_then(|from_now| Duration::from_std(from_now).ok())
+ .map(|duration| HumanTime::from(duration).to_text_en(Accuracy::Rough, Tense::Past))
+ .unwrap_or_default()
}