浏览代码

Error handling 🤷‍♂️

master
Dylan Baker 6 年前
父节点
当前提交
a73746be3f
共有 1 个文件被更改,包括 11 次插入0 次删除
  1. 11
    0
      src/main.rs

+ 11
- 0
src/main.rs 查看文件

78
 
78
 
79
 fn main() {
79
 fn main() {
80
     let cwd = env::current_dir().expect("Couldn't read current directory");
80
     let cwd = env::current_dir().expect("Couldn't read current directory");
81
+
82
+    match fs::create_dir(cwd.join("public")) {
83
+        Ok(_) => {},
84
+        Err(err) => {
85
+            match err.kind() {
86
+                std::io::ErrorKind::AlreadyExists => {},
87
+                _ => panic!(err)
88
+            }
89
+        }
90
+    }
91
+
81
     let layout = fs::read_to_string(&cwd.join("templates").join("layout.html"))
92
     let layout = fs::read_to_string(&cwd.join("templates").join("layout.html"))
82
         .expect("Couldn't find layout template");
93
         .expect("Couldn't find layout template");
83
     let post_paths = read_posts_dir(&cwd.join("posts"));
94
     let post_paths = read_posts_dir(&cwd.join("posts"));

正在加载...
取消
保存