瀏覽代碼

cargo fmt

Mathias Gottschlag 5 年之前
父節點
當前提交
1c3dae7000
共有 2 個文件被更改,包括 11 次插入6 次删除
  1. 5
    2
      src/bin/client.rs
  2. 6
    4
      src/bin/server.rs

+ 5
- 2
src/bin/client.rs 查看文件

2
 use std::io;
2
 use std::io;
3
 use std::sync::{Arc, Mutex};
3
 use std::sync::{Arc, Mutex};
4
 
4
 
5
+use tokio::io::{AsyncReadExt, AsyncWriteExt};
5
 use tokio::net::{UnixListener, UnixStream};
6
 use tokio::net::{UnixListener, UnixStream};
6
 use tokio::stream::StreamExt;
7
 use tokio::stream::StreamExt;
7
-use tokio::io::{AsyncWriteExt, AsyncReadExt};
8
 
8
 
9
 use twfss::Database;
9
 use twfss::Database;
10
 
10
 
61
                     Err(e) => {
61
                     Err(e) => {
62
                         // Log error and try to send it to the stream.
62
                         // Log error and try to send it to the stream.
63
                         // TODO
63
                         // TODO
64
-                        stream.write_all(format!("Error: {:?}", e).as_bytes()).await.ok();
64
+                        stream
65
+                            .write_all(format!("Error: {:?}", e).as_bytes())
66
+                            .await
67
+                            .ok();
65
                     }
68
                     }
66
                 };
69
                 };
67
             }
70
             }

+ 6
- 4
src/bin/server.rs 查看文件

1
+use std::fs::create_dir_all;
1
 use std::net::SocketAddr;
2
 use std::net::SocketAddr;
2
 use std::sync::{Arc, Mutex};
3
 use std::sync::{Arc, Mutex};
3
-use std::fs::create_dir_all;
4
 
4
 
5
 use async_tungstenite::accept_async;
5
 use async_tungstenite::accept_async;
6
+use futures::sink::SinkExt;
7
+use futures_tokio_compat::Compat;
6
 use log::*;
8
 use log::*;
7
 use tokio::net::{TcpListener, TcpStream};
9
 use tokio::net::{TcpListener, TcpStream};
8
 use tokio::stream::StreamExt;
10
 use tokio::stream::StreamExt;
9
-use futures_tokio_compat::Compat;
10
-use futures::sink::SinkExt;
11
 
11
 
12
 use twfss::Database;
12
 use twfss::Database;
13
 
13
 
65
 // TODO: Robust error handling.
65
 // TODO: Robust error handling.
66
 
66
 
67
 async fn accept_connection(peer: SocketAddr, stream: TcpStream) {
67
 async fn accept_connection(peer: SocketAddr, stream: TcpStream) {
68
-    let mut ws_stream = accept_async(Compat::new(stream)).await.expect("Failed to accept");
68
+    let mut ws_stream = accept_async(Compat::new(stream))
69
+        .await
70
+        .expect("Failed to accept");
69
 
71
 
70
     info!("New WebSocket connection from {}.", peer);
72
     info!("New WebSocket connection from {}.", peer);
71
 
73
 

Loading…
取消
儲存