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::prelude::IteratorRandom;
use rand::thread_rng; use rand::thread_rng;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::net::SocketAddr;
/// User
pub struct User {
pub name: String,
pub addr: SocketAddr,
}
/// New game request structure /// New game request structure
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]

View file

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

View file

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