mv structs to lib
This commit is contained in:
parent
aa02be7c55
commit
9a8a87662e
3 changed files with 11 additions and 8 deletions
|
@ -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)]
|
||||
|
|
|
@ -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\
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue