mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +00:00
refactor(commands): also use smolstr for commands themselves
This commit is contained in:
parent
af523a4c23
commit
b9867e7ea3
3 changed files with 12 additions and 8 deletions
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue