got api working ish, I need to clean this code up a lot

This commit is contained in:
2026-04-27 17:26:49 +01:00
parent c87949bc4b
commit c53138b163
13 changed files with 1143 additions and 43 deletions
+34 -4
View File
@@ -1,10 +1,38 @@
use std::fs;
use std::collections::HashMap;
use std::
{
fs,
thread,
collections::HashMap,
sync::{Arc, Mutex, mpsc},
};
use serde::{Deserialize, Serialize};
use tokio::runtime::Runtime;
use tokio::task;
use warp::Filter;
mod parsing;
mod character;
mod config;
mod api;
fn main() {
#[tokio::main]
async fn main() {
let (tx,rx) = mpsc::channel();
let mut data_to_send = Arc::new(Mutex::new(api::Data_to_send
{
action_type: "initialise".to_string(),
content: "".to_string(),
character: "".to_string(),
}));
let data = Arc::clone(&data_to_send);
let tx_clone = tx.clone();
// Spawn a thread for warp
tokio::spawn(
async move {
api::api_process(data, tx_clone).await;
});
println!("and continue");
let mut characters = HashMap::<String, character::Character>::new();
let file_contents: String = fs::read_to_string("stories/story.ha").unwrap();
// Split the file contents into tokens
@@ -12,7 +40,9 @@ fn main() {
.split_whitespace()
.collect();
// Run the parsing process
match parsing::token_parse(&tokens, &mut characters) {
let data_clone = Arc::clone(&data_to_send);
match parsing::token_parse(&tokens, &mut characters, data_clone, &rx).await
{
Ok(()) => println!("Program exited successfully"),
Err(error) => println!("{}", error),
}