Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
BradenEverson committed Nov 2, 2024
1 parent 3254ace commit 962650a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
13 changes: 13 additions & 0 deletions earthmover-hivemind/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@ hyper-util = { version = "0.1.6", features = ["full", "tokio"] }
tokio = { version = "1.39.2", features = ["full"] }
uuid = { version = "1.11.0", features = ["v4"] }
earthmover-achiever = { path = "../earthmover-achiever" }

[lints.rust]
missing_docs = "warn"
nonstandard-style = "warn"
rust-2018-idioms = "warn"
rust-2021-compatibility = "warn"
rust-2024-compatibility = "warn"

[lints.rustdoc]
broken_intra_doc_links = "warn"

[lints.clippy]
missing_docs_in_private_items = "warn"
10 changes: 3 additions & 7 deletions earthmover-hivemind/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
//! The server crate responsible for handling incoming data and simulating physics of the
//! environment

use earthmover_hivemind::new_state;
use hyper::server::conn::http1;
use hyper_util::rt::TokioIo;
use tokio::net::TcpListener;
use earthmover_hivemind::new_state;

#[tokio::main]
async fn main() {
let (state, service) = new_state();
let (_state, service) = new_state();

let listener = TcpListener::bind("0.0.0.0:1940").await.unwrap();
println!(
"Listening on http://localhost:{}",
listener.local_addr().unwrap().port()
);

let state_clone = state.clone();
let connection_handler = async move {
loop {
// Handle connections
Expand All @@ -29,10 +28,7 @@ async fn main() {

let service = service.clone();
tokio::spawn(async move {
if let Err(e) = http1::Builder::new()
.serve_connection(io, service)
.await
{
if let Err(e) = http1::Builder::new().serve_connection(io, service).await {
eprintln!("Error serving connection: {}", e);
}
});
Expand Down
20 changes: 16 additions & 4 deletions earthmover-hivemind/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,33 @@ use std::sync::Arc;

use tokio::sync::RwLock;

use crate::state::{message::{MessageSender, ResponseReceiver}, ServerState};
use crate::state::{
message::{MessageSender, ResponseReceiver},
ServerState,
};

/// A server service handler
#[derive(Clone)]
pub struct ServerService {
/// The current state this service works with respect to
pub state: Arc<RwLock<ServerState>>,
/// The responses sent back
pub response_queue: Arc<RwLock<ResponseReceiver>>,
/// The message send channel
pub message_sender: MessageSender
pub message_sender: MessageSender,
}

impl ServerService {
/// Creates a new service instance
pub fn new(state: Arc<RwLock<ServerState>>, response_queue: ResponseReceiver, message_sender: MessageSender) -> Self {
Self { state, response_queue: Arc::new(RwLock::new(response_queue)), message_sender }
pub fn new(
state: Arc<RwLock<ServerState>>,
response_queue: ResponseReceiver,
message_sender: MessageSender,
) -> Self {
Self {
state,
response_queue: Arc::new(RwLock::new(response_queue)),
message_sender,
}
}
}
5 changes: 4 additions & 1 deletion earthmover-hivemind/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ pub struct ServerState {
impl ServerState {
/// Creates a new state
pub fn new(message_queue: MessageReceiver, response_sender: ResponseSender) -> Self {
Self { message_queue, response_sender }
Self {
message_queue,
response_sender,
}
}
}

0 comments on commit 962650a

Please sign in to comment.