Clippy lint fixing

This commit is contained in:
2026-05-14 15:31:48 +01:00
parent 7b9d52e94d
commit a55053dc97
5 changed files with 67 additions and 55 deletions
+23 -24
View File
@@ -18,10 +18,10 @@ use crate::
// Parse the tokens in a file
// Returns success or an error string
pub async fn token_parse(
pub fn token_parse(
tokens: &Vec<&str>,
characters: Arc<Mutex<HashMap::<String, character::Character>>>,
data_to_send: Arc<Mutex<api::DataToSend>>,
data_to_send: &Arc<Mutex<api::DataToSend>>,
rx: &Receiver<(bool,usize)>,
) -> Result<(),String>
{
@@ -31,7 +31,7 @@ pub async fn token_parse(
{
warn!("Some issue with api");
// TOD eh?
};
}
info!("Client has connected");
// Run an infinite loop
'parse_loop: loop
@@ -40,14 +40,14 @@ pub async fn token_parse(
let token = tokens
.get(index)
.ok_or_else(|| "File unexpectedly reached termination point".to_string())?;
debug!("{}: {}",index, token);
debug!("{index}: {token}");
// The instructions are related to characters
if token.starts_with('@')
{
let character_name: String = token.chars().skip(1).collect();
debug!("Doing something with a character: {}", character_name);
debug!("Doing something with a character: {character_name}");
// The index is incremented to after the character's instructions
index = match character_parse(index+1, tokens, character_name, &characters, &data_to_send).await
index = match character_parse(index+1, tokens, character_name, &characters, &data_to_send)
{
Ok(increment) => increment,
Err(error) => return Err(error),
@@ -65,7 +65,7 @@ pub async fn token_parse(
},
"choice" =>
{
let (_,jump_points) = match choice_parse(index+1, tokens, &data_to_send).await
let (_,jump_points) = match choice_parse(index+1, tokens, &data_to_send)
{
Ok((increment,jump_point)) => (increment,jump_point),
Err(error) => return Err(error),
@@ -76,13 +76,13 @@ pub async fn token_parse(
Ok((_,choice)) => (None::<bool>, choice),
Err(err) =>
{
warn!("Error receiving choice from client, defaulting to choice 0 {}", err);
warn!("Error receiving choice from client, defaulting to choice 0 {err}");
(None::<bool>, 0)
}
};
index = jump_points[choice];
info!("CHOICE command with {} choices", jump_points.len());
debug!("{:?} {} {}",jump_points, choice, index);
info!("CHOICE command with {} choices",jump_points.len());
debug!("{jump_points:?} {choice} {index}");
continue 'parse_loop
},
"or" =>
@@ -91,7 +91,7 @@ pub async fn token_parse(
index += match strings::closing_char(&tokens[index..], '{','}') // TODO eh
{
Ok(index) => index,
Err(_) => return Err(String::from("Unable to find closing brace to OR command")),
Err(()) => return Err(String::from("Unable to find closing brace to OR command")),
};
continue
},
@@ -102,20 +102,19 @@ pub async fn token_parse(
},
_ =>
{
warn!("Invalid command: {}", token);
warn!("Invalid command: {token}");
}
};
}
}
if rx.recv().is_err()
{
warn!("Some issue with api");
continue
}
}
}
// Parse the options in a choice clause and returns the idexes of the code blocks
async fn choice_parse
fn choice_parse
(
index: usize,
tokens: &[&str],
@@ -141,18 +140,19 @@ async fn choice_parse
choice_indeces.push(sum_index+2);
sum_index += strings::closing_char(&tokens[sum_index..], '{','}').unwrap() + 1; //TODO eh
}
debug!("{:?}", choices);
debug!("{choices:?}");
let mut data = data_to_send.lock().unwrap();
data.action_type = String::from("choice");
data.content = "".to_string();
data.character = "".to_string();
data.content = String::new();
data.character = String::new();
data.choices = choices; //TODO
Ok((sum_index + 1, choice_indeces))
}
// Parsing character related instructions
// TODO only send relevant tokens
#[allow(unused_variables)] async fn character_parse
#[allow(unused_variables)]
fn character_parse
(
index: usize,
tokens: &Vec<&str>,
@@ -172,18 +172,17 @@ async fn choice_parse
// to the client
"says" =>
{
info!("SAYS command with character {}", character_name);
info!("SAYS command with character {character_name}");
match strings::extract_quoted(&tokens[sum_index+1..]) // TODO increment to after the string
{
Some((output_string, counter)) =>
{
debug!("{}", output_string);
debug!("{output_string}");
sum_index += counter;
debug!("{}",sum_index);
let mut data = data_to_send.lock().unwrap();
data.action_type = String::from("output");
data.content = output_string;
data.character = character_name.clone();
data.character = character_name;
data.choices = vec![];
},
None => return Err(String::from("Unable to read string")),
@@ -191,7 +190,7 @@ async fn choice_parse
},
// Catch all condition, if the instruction is unrecognised as a
// character command
_ => return Err(format!("Invalid command: {}", token)),
_ => return Err(format!("Invalid command: {token}")),
}
sum_index += 1;
Ok(sum_index)