浏览代码

Formatting

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

+ 24
- 10
src/main.rs 查看文件

53
 async fn read_all_posts() -> Result<Vec<Post>, Error> {
53
 async fn read_all_posts() -> Result<Vec<Post>, Error> {
54
     let path = match get_posts_directory() {
54
     let path = match get_posts_directory() {
55
         Ok(p) => Ok(p),
55
         Ok(p) => Ok(p),
56
-        Err(_) => Err(Error::new(ErrorKind::Other, "POSTS_DIR variable is not set"))
56
+        Err(_) => Err(Error::new(
57
+            ErrorKind::Other,
58
+            "POSTS_DIR variable is not set",
59
+        )),
57
     }?;
60
     }?;
58
     let mut posts: Vec<Post> = vec![];
61
     let mut posts: Vec<Post> = vec![];
59
 
62
 
60
     let files = match read_dir(path) {
63
     let files = match read_dir(path) {
61
         Ok(f) => Ok(f),
64
         Ok(f) => Ok(f),
62
-        Err(_) => Err(Error::new(ErrorKind::Other, "Posts directory does not exist"))
65
+        Err(_) => Err(Error::new(
66
+            ErrorKind::Other,
67
+            "Posts directory does not exist",
68
+        )),
63
     }?;
69
     }?;
64
 
70
 
65
     for file in files {
71
     for file in files {
67
         if let Some("json") = file.path().extension().and_then(OsStr::to_str) {
73
         if let Some("json") = file.path().extension().and_then(OsStr::to_str) {
68
             let contents = match read_to_string(file.path()).await {
74
             let contents = match read_to_string(file.path()).await {
69
                 Ok(c) => Ok(c),
75
                 Ok(c) => Ok(c),
70
-                Err(_) => Err(Error::new(ErrorKind::Other, format!("Error reading post {:?}", file.path())))
76
+                Err(_) => Err(Error::new(
77
+                    ErrorKind::Other,
78
+                    format!("Error reading post {:?}", file.path()),
79
+                )),
71
             }?;
80
             }?;
72
             let mut post: Post = match serde_json::from_str(&contents) {
81
             let mut post: Post = match serde_json::from_str(&contents) {
73
                 Ok(p) => Ok(p),
82
                 Ok(p) => Ok(p),
74
-                Err(_) => Err(Error::new(ErrorKind::Other, format!("Error deserializing post")))
83
+                Err(_) => Err(Error::new(
84
+                    ErrorKind::Other,
85
+                    format!("Error deserializing post"),
86
+                )),
75
             }?;
87
             }?;
76
             post.body = post.body.replace("\n", "<br>");
88
             post.body = post.body.replace("\n", "<br>");
77
             posts.push(post);
89
             posts.push(post);
172
                 Ok(tide::Redirect::new("/"))
184
                 Ok(tide::Redirect::new("/"))
173
             } else {
185
             } else {
174
                 req.session_mut().remove("logged_in");
186
                 req.session_mut().remove("logged_in");
175
-                req.session_mut().insert("flash_error", "Invalid credentials")?;
187
+                req.session_mut()
188
+                    .insert("flash_error", "Invalid credentials")?;
176
                 Ok(tide::Redirect::new("/login"))
189
                 Ok(tide::Redirect::new("/login"))
177
             }
190
             }
178
         });
191
         });
179
 
192
 
180
-    app.at("/logout").get(|mut req: tide::Request<()>| async move {
181
-        req.session_mut().remove("logged_in");
182
-        req.session_mut().insert("logged_in", false)?;
183
-        Ok(tide::Redirect::new("/"))
184
-    });
193
+    app.at("/logout")
194
+        .get(|mut req: tide::Request<()>| async move {
195
+            req.session_mut().remove("logged_in");
196
+            req.session_mut().insert("logged_in", false)?;
197
+            Ok(tide::Redirect::new("/"))
198
+        });
185
 
199
 
186
     app.listen("127.0.0.1:8080").await?;
200
     app.listen("127.0.0.1:8080").await?;
187
 
201
 

正在加载...
取消
保存