Browse Source

Pass cwd around

master
Dylan Baker 6 years ago
parent
commit
858dd51bbc
1 changed files with 4 additions and 5 deletions
  1. 4
    5
      src/main.rs

+ 4
- 5
src/main.rs View File

36
     }
36
     }
37
 }
37
 }
38
 
38
 
39
-fn read_posts_dir() -> fs::ReadDir {
40
-    let cwd = env::current_dir()
41
-        .expect("Couldn't read current directory")
42
-        .join("posts");
39
+fn read_posts_dir(cwd: &path::PathBuf) -> fs::ReadDir {
43
     match fs::read_dir(cwd) {
40
     match fs::read_dir(cwd) {
44
         Ok(posts) => posts,
41
         Ok(posts) => posts,
45
         Err(err) => panic!(err),
42
         Err(err) => panic!(err),
47
 }
44
 }
48
 
45
 
49
 fn main() {
46
 fn main() {
50
-    let post_paths = read_posts_dir();
47
+    let cwd = env::current_dir()
48
+        .expect("Couldn't read current directory");
49
+    let post_paths = read_posts_dir(&cwd.join("posts"));
51
     for path in post_paths {
50
     for path in post_paths {
52
         match path {
51
         match path {
53
             Ok(p) => {
52
             Ok(p) => {

Loading…
Cancel
Save