Fixed some clippy lints
This commit is contained in:
+12
-13
@@ -40,9 +40,8 @@ pub async fn api_process
|
||||
// This data must be passed through to the api route in order to be used
|
||||
let happening_queue_filter = warp::any().map(move || Arc::clone(&happening_queue));
|
||||
let characters_filter = warp::any().map(move || Arc::clone(&characters));
|
||||
let tx_filter = warp::any().map(move || tx.clone());
|
||||
let tx_filter2 = tx_filter.clone();
|
||||
let tx_filter3 = tx_filter.clone();
|
||||
let tx_filter1 = warp::any().map(move || tx.clone());
|
||||
let tx_filter2 = tx_filter1.clone();
|
||||
|
||||
info!("Running server");
|
||||
|
||||
@@ -50,13 +49,13 @@ pub async fn api_process
|
||||
let main = warp::path("happening")
|
||||
.and(warp::get())
|
||||
.and(happening_queue_filter)
|
||||
.and(tx_filter)
|
||||
// Perform this code on a GET request
|
||||
.map(|queue: Arc<Mutex<VecDeque<DataToSend>>>, tx_handle: Sender<(usize,String)>|
|
||||
.map(|queue: Arc<Mutex<VecDeque<DataToSend>>>|
|
||||
{
|
||||
//debug!("GET: {state:?}");
|
||||
let mut queue = queue.lock().unwrap();
|
||||
let mut queue = queue.lock().unwrap_or_exit("Queue Mutex was poisoned", 2);
|
||||
let reply = queue.pop_front().unwrap_or_default();
|
||||
drop(queue);
|
||||
warp::reply::json(&reply) // Send the reply data (data_to_send formatted as JSON)
|
||||
}).boxed();
|
||||
let characters = warp::path("character")
|
||||
@@ -90,7 +89,7 @@ pub async fn api_process
|
||||
let choice = warp::path("choice")
|
||||
.and(warp::post())
|
||||
.and(warp::body::json())
|
||||
.and(tx_filter2)
|
||||
.and(tx_filter1)
|
||||
.map(|index: usize, tx_handle: Sender<(usize,String)>| {
|
||||
debug!("Choice: {index}");
|
||||
let _ = tx_handle.send((index,String::new()));
|
||||
@@ -100,7 +99,7 @@ pub async fn api_process
|
||||
let input = warp::path("input")
|
||||
.and(warp::post())
|
||||
.and(warp::body::json())
|
||||
.and(tx_filter3)
|
||||
.and(tx_filter2)
|
||||
.map(|input: String, tx_handle: Sender<(usize, String)>|
|
||||
{
|
||||
let _ = tx_handle.send((0,input));
|
||||
@@ -122,16 +121,16 @@ pub fn modify_data // TODO rename
|
||||
happening_queue: &Arc<Mutex<VecDeque<DataToSend>>>,
|
||||
action_type: String,
|
||||
content: String,
|
||||
character_name: String,
|
||||
character: String,
|
||||
choices: Vec<String>,
|
||||
)
|
||||
{
|
||||
let mut queue = happening_queue.lock().unwrap_or_exit("Data to send Mutex was poisoned",2);
|
||||
let new_data = DataToSend {
|
||||
action_type: action_type,
|
||||
content: content,
|
||||
character: character_name,
|
||||
choices: choices,
|
||||
action_type,
|
||||
content,
|
||||
character,
|
||||
choices,
|
||||
};
|
||||
queue.push_back(new_data);
|
||||
drop(queue);
|
||||
|
||||
+5
-10
@@ -32,17 +32,16 @@ pub fn token_parse(
|
||||
let mut index: usize = 0;
|
||||
info!("Client has connected");
|
||||
// Run an infinite loop
|
||||
'parse_loop: loop
|
||||
loop
|
||||
{
|
||||
debug!("Reading {index}");
|
||||
// Get the next token
|
||||
let token: String = match tokens.get(index)
|
||||
match tokens.get(index)
|
||||
{
|
||||
Some(tokenise::Token::Keyword(token)) =>
|
||||
{
|
||||
if token.to_lowercase().as_str() == "end" { return Ok(()); };
|
||||
index = keyword_parse::keyword_parse(tokens, token.to_string(), index, characters, happening_queue, labels, rx).unwrap();
|
||||
continue 'parse_loop;
|
||||
if token.to_lowercase().as_str() == "end" { return Ok(()); }
|
||||
index = keyword_parse::keyword_parse(tokens, token, index, happening_queue, labels, rx)?;
|
||||
},
|
||||
// Ignore closing braces and jump over opening brace blocks
|
||||
Some(tokenise::Token::Bracket((bracket,new_index))) =>
|
||||
@@ -53,7 +52,6 @@ pub fn token_parse(
|
||||
warn!("Unexpected brace block, jumping over...");
|
||||
index = new_index + 1;
|
||||
}
|
||||
continue 'parse_loop
|
||||
},
|
||||
// Handle a character
|
||||
Some(tokenise::Token::Character(character_name)) => // TODO add support for narrator
|
||||
@@ -67,17 +65,14 @@ pub fn token_parse(
|
||||
increment
|
||||
},
|
||||
};
|
||||
continue 'parse_loop
|
||||
}
|
||||
Some(_) =>
|
||||
{
|
||||
warn!("Unexpected token");
|
||||
index += 1;
|
||||
continue 'parse_loop
|
||||
},
|
||||
None => return Err("File unexpectedly reached termination point".to_string()),
|
||||
};
|
||||
debug!("{index}: {token}");
|
||||
}
|
||||
// The instructions are related to characters
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::
|
||||
{
|
||||
tokenise,
|
||||
character,
|
||||
api,
|
||||
|
||||
HashMap,
|
||||
@@ -16,9 +15,8 @@ use crate::
|
||||
|
||||
pub fn keyword_parse(
|
||||
tokens: &[tokenise::Token],
|
||||
token: String,
|
||||
token: &str,
|
||||
mut index: usize,
|
||||
characters: &Arc<Mutex<HashMap::<String, character::Character>>>,
|
||||
happening_queue: &Arc<Mutex<VecDeque<api::DataToSend>>>,
|
||||
labels: &HashMap<String, usize>,
|
||||
rx: &Receiver<(usize,String)>,
|
||||
|
||||
@@ -8,6 +8,7 @@ pub enum Token
|
||||
{
|
||||
String(String),
|
||||
Keyword(String), // Keywords aren't checked for validity in this stage
|
||||
#[allow(dead_code)] // This is unused rn, but am going to add it later
|
||||
Identifier(String),
|
||||
Bracket((Bracket,usize)), // Stores the index of the matching deliminator
|
||||
Character(String),
|
||||
|
||||
Reference in New Issue
Block a user