mv structs to lib

This commit is contained in:
Adam 2024-07-21 00:59:21 -04:00
parent aa02be7c55
commit 9a8a87662e
3 changed files with 11 additions and 8 deletions

View file

@ -2,6 +2,13 @@ use anyhow::Result;
use rand::prelude::IteratorRandom;
use rand::thread_rng;
use serde::{Deserialize, Serialize};
use std::net::SocketAddr;
/// User
pub struct User {
pub name: String,
pub addr: SocketAddr,
}
/// New game request structure
#[derive(Debug, Deserialize)]

View file

@ -8,14 +8,11 @@ use axum::{
};
use futures::{SinkExt, StreamExt};
use std::{net::SocketAddr, sync::Arc};
use libcards::*;
pub mod message_handler;
use crate::message_handler::*;
pub struct User {
name: String,
addr: SocketAddr,
}
fn greeting(state: &Arc<AppState>) -> String {
format!(
"{:#?} Card packs loaded\n\

View file

@ -1,7 +1,6 @@
use crate::api::{greeting, Message, User};
use crate::AppState;
use crate::Arc;
use crate::CAHGame;
use libcards::*;
pub async fn message_handler(message: Message, state: &Arc<AppState>, who: &User) {
@ -15,9 +14,9 @@ pub async fn message_handler(message: Message, state: &Arc<AppState>, who: &User
if let Ok(new_game_object) = CAHGame::new(new_game) {
let _ = tx.send(format!("{:#?}", &new_game_object.players[0].white));
state.games.lock().unwrap().push(new_game_object);
let _update = tx.send(greeting(&state));
let _update = tx.send(greeting(state));
} else {
let _res = tx.send(format!("error creating game"));
let _res = tx.send(String::from("error creating game"));
}
} else {
// just echo