refactor(commands): also use smolstr for commands themselves

This commit is contained in:
dusk 2025-01-04 07:43:55 +09:00
parent af523a4c23
commit b9867e7ea3
No known key found for this signature in database
3 changed files with 12 additions and 8 deletions

View file

@ -18,26 +18,28 @@ pub mod server_config;
pub mod switch;
pub mod system;
use smol_str::SmolStr;
use crate::{command, token::Token};
#[derive(Clone)]
pub struct Command {
// TODO: fix hygiene
pub tokens: Vec<Token>,
pub help: String,
pub cb: String,
pub help: SmolStr,
pub cb: SmolStr,
}
impl Command {
pub fn new(
tokens: impl IntoIterator<Item = Token>,
help: impl ToString,
cb: impl ToString,
help: impl Into<SmolStr>,
cb: impl Into<SmolStr>,
) -> Self {
Self {
tokens: tokens.into_iter().collect(),
help: help.to_string(),
cb: cb.to_string(),
help: help.into(),
cb: cb.into(),
}
}
}

View file

@ -84,7 +84,7 @@ fn parse_command(input: String) -> CommandResult {
if let Some(command_ref) = local_tree.current_command_key {
return CommandResult::Ok {
command: ParsedCommand {
command_ref: command_ref.to_owned(),
command_ref: command_ref.into(),
args,
flags,
},

View file

@ -1,9 +1,11 @@
use smol_str::SmolStr;
use crate::{commands::Command, Token};
use std::{cmp::Ordering, collections::HashMap};
#[derive(Debug, Clone)]
pub struct TreeBranch {
pub current_command_key: Option<String>,
pub current_command_key: Option<SmolStr>,
/// branches.keys(), but sorted by specificity
pub possible_tokens: Vec<Token>,
pub branches: HashMap<Token, TreeBranch>,