changeset 31:26111ba2fea1

replace in map
author AnaTofuZ <anatofuz@gmail.com>
date Sat, 21 Nov 2020 16:59:29 +0900
parents f4b655fae2a3
children ae7ba39dfcbe
files src/command.rs
diffstat 1 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/command.rs	Sat Nov 21 16:51:11 2020 +0900
+++ b/src/command.rs	Sat Nov 21 16:59:29 2020 +0900
@@ -19,17 +19,22 @@
 
 pub fn templates() -> io::Result<()> {
     let mut entries = fs::read_dir(TEMPLATE_DIR)?
-        .map(|res| res.map(|e| e.path().display().to_string()))
+        .map(|res| {
+            res.map(|e| {
+                e.path()
+                    .display()
+                    .to_string()
+                    .replace(TEMPLATE_DIR, "")
+                    .replace(TEMPLATE_SUFFIX, "")
+                    .replace(TEMPLATE_FILE_EXTENSION, "")
+            })
+        })
         .collect::<Result<Vec<_>, io::Error>>()?;
 
     entries.sort();
 
     for entry in entries {
-        let template_vm = entry
-            .replace(TEMPLATE_DIR, "")
-            .replace(TEMPLATE_SUFFIX, "")
-            .replace(TEMPLATE_FILE_EXTENSION, "");
-        println!("{}", template_vm);
+        println!("{}", entry);
     }
 
     Ok(())