diff options
| author | Fuwn <[email protected]> | 2024-06-03 15:23:14 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-06-03 15:23:14 -0700 |
| commit | 19010055c88fd7aac23f3ce39fa6a5ec1cbf9a52 (patch) | |
| tree | 22353b8c7a78b83c992b7bfb60c024fee6f78e3e /crates/whirl_server/src/lib.rs | |
| parent | chore(rustfmt): add new rules (diff) | |
| download | whirl-19010055c88fd7aac23f3ce39fa6a5ec1cbf9a52.tar.xz whirl-19010055c88fd7aac23f3ce39fa6a5ec1cbf9a52.zip | |
format: rustfmt with new rules
Diffstat (limited to 'crates/whirl_server/src/lib.rs')
| -rw-r--r-- | crates/whirl_server/src/lib.rs | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/crates/whirl_server/src/lib.rs b/crates/whirl_server/src/lib.rs index 2567cf7..e8fdb6f 100644 --- a/crates/whirl_server/src/lib.rs +++ b/crates/whirl_server/src/lib.rs @@ -20,10 +20,8 @@ )] #![allow(non_local_definitions, dead_code)] -#[macro_use] -extern crate log; -#[macro_use] -extern crate async_trait; +#[macro_use] extern crate log; +#[macro_use] extern crate async_trait; mod cmd; mod interaction; @@ -33,15 +31,15 @@ mod distributor; mod hub; mod packet_parser; -use std::{error::Error, fmt, net::SocketAddr, sync::Arc}; - -use tokio::{ - net::{TcpListener, TcpStream}, - sync::Mutex, +use { + crate::interaction::shared::Shared, + std::{error::Error, fmt, net::SocketAddr, sync::Arc}, + tokio::{ + net::{TcpListener, TcpStream}, + sync::Mutex, + }, }; -use crate::interaction::shared::Shared; - /// The type of server the `listen` method of the `Server` trait will /// implemented for. #[derive(Debug)] @@ -54,12 +52,17 @@ pub enum ServerType { } // https://stackoverflow.com/a/32712140/14452787 impl fmt::Display for ServerType { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self) } + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{:?}", self) + } } #[async_trait] pub trait Server { - async fn listen(address: &str, server_type: ServerType) -> Result<(), Box<dyn Error>> { + async fn listen( + address: &str, + server_type: ServerType, + ) -> Result<(), Box<dyn Error>> { let listener = TcpListener::bind(address).await?; let state = Arc::new(Mutex::new(Shared::new())); let mut counter = 0; @@ -86,7 +89,8 @@ pub trait Server { error!("an error occurred: {}", e); } - if std::env::var("EXIT_ON_CLIENT_DISCONNECT").unwrap_or_else(|_| "false".to_string()) + if std::env::var("EXIT_ON_CLIENT_DISCONNECT") + .unwrap_or_else(|_| "false".to_string()) == "true" { std::process::exit(0); @@ -104,10 +108,11 @@ pub trait Server { } pub mod make { - use tokio::task::JoinHandle; - use whirl_config::Config; - - use crate::{Server, ServerType}; + use { + crate::{Server, ServerType}, + tokio::task::JoinHandle, + whirl_config::Config, + }; /// Spawn and return a thread handle for a Distributor sub-server. /// @@ -158,8 +163,7 @@ pub mod make { /// - A panic may occur if the TCP server is unable to bind the specified /// port. #[must_use] - #[deprecated( - note = "The `distributor` and `hub` functions are more extensible, use them instead." - )] + #[deprecated(note = "The `distributor` and `hub` functions are more \ + extensible, use them instead.")] pub fn all() -> Vec<JoinHandle<()>> { vec![distributor(), hub()] } } |