瀏覽代碼

Immutability

master
Dylan Baker 6 年之前
父節點
當前提交
ba59bd1b7f
共有 1 個檔案被更改,包括 5 行新增6 行删除
  1. 5
    6
      src/main.rs

+ 5
- 6
src/main.rs 查看文件

108
             .expect("Couldn't find post listing item template");
108
             .expect("Couldn't find post listing item template");
109
 
109
 
110
     let post_paths = read_posts_dir(&cwd.join("posts"));
110
     let post_paths = read_posts_dir(&cwd.join("posts"));
111
-    let mut posts: Vec<Post> = vec![];
112
-    for path in post_paths {
113
-        match path {
111
+    let posts = post_paths
112
+        .into_iter()
113
+        .map(|path| match path {
114
             Ok(p) => {
114
             Ok(p) => {
115
                 let post = parse_post(p.path());
115
                 let post = parse_post(p.path());
116
                 render_post(&cwd, &layout_template, &post_template, &post);
116
                 render_post(&cwd, &layout_template, &post_template, &post);
117
-                posts.push(post);
117
+                post
118
             }
118
             }
119
             Err(err) => panic!(err),
119
             Err(err) => panic!(err),
120
-        }
121
-    }
120
+        }).collect();
122
 
121
 
123
     render_post_listing(&cwd, &layout_template, &post_item_template, &posts);
122
     render_post_listing(&cwd, &layout_template, &post_item_template, &posts);
124
 }
123
 }

Loading…
取消
儲存