summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorJomar Milan <jomarm@jomarm.com>2026-06-19 17:50:59 -0700
committerJomar Milan <jomarm@jomarm.com>2026-06-19 17:50:59 -0700
commita83eb7452b5d6bded88dca083b59df833f6dbd2f (patch)
tree2a50a0ffeb94a0c1ffc3fbc8ef4946f2bfc1d229 /src/main.rs
parentd624bf54951a3b7481f0f181f5866b21f8d917f5 (diff)
Use enum for storing player color
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index f4782ac..c05d3c6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -6,7 +6,6 @@
#![warn(
missing_docs,
- missing_copy_implementations,
missing_debug_implementations
)]
@@ -14,8 +13,9 @@ mod play;
mod session;
mod template;
+use std::array;
use crate::play::handle_play;
-use crate::session::{HandObject, Session};
+use crate::session::{HandObject, PlayerColor, Session};
use crate::template::{IndexTemplate, SessionTemplate};
use askama::Template;
use axum::extract::{Path, Query, State, WebSocketUpgrade};
@@ -132,11 +132,23 @@ async fn update_hands(
) -> StatusCode {
let mut sessions = state.sessions.write().unwrap();
+ let hand = array::from_fn(|i| {
+ let color = PlayerColor::try_from(i);
+ let color = color.as_ref().map(AsRef::as_ref);
+ if let Ok(color) = color {
+ // It would not be necessary to clone here if the vector could be moved, which could be
+ // done if payload was mutable
+ payload.get(color).cloned().unwrap_or_else(Vec::new)
+ } else {
+ Vec::new()
+ }
+ });
+
match sessions.get_mut(&id) {
Some(session) => {
let mut session = session.lock().unwrap();
- session.update_hands(payload);
+ session.update_hands(hand);
StatusCode::NO_CONTENT
}