mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +00:00
refactor(commands): remove general From array impl for tokens because it doesnt make sense
This commit is contained in:
parent
c6db96115e
commit
2a66e8b4cf
3 changed files with 12 additions and 20 deletions
|
|
@ -39,10 +39,13 @@ impl Command {
|
|||
pub fn new(tokens: impl IntoIterator<Item = Token>, cb: impl Into<SmolStr>) -> Self {
|
||||
let tokens = tokens.into_iter().collect::<Vec<_>>();
|
||||
assert!(tokens.len() > 0);
|
||||
// figure out which token to parse / put flags after
|
||||
// (by default, put flags after the last token)
|
||||
let mut parse_flags_before = tokens.len();
|
||||
let mut was_parameter = true;
|
||||
for (idx, token) in tokens.iter().enumerate().rev() {
|
||||
match token {
|
||||
// we want flags to go before any parameters
|
||||
Token::Parameter(_, _) | Token::Any(_) => {
|
||||
parse_flags_before = idx;
|
||||
was_parameter = true;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ fn main() {
|
|||
}
|
||||
} else {
|
||||
for command in cmds::all() {
|
||||
println!("{}", command);
|
||||
println!("{} - {}", command, command.help);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use std::{
|
|||
sync::Arc,
|
||||
};
|
||||
|
||||
use smol_str::{SmolStr, ToSmolStr};
|
||||
use smol_str::SmolStr;
|
||||
|
||||
use crate::{parameter::Parameter, Parameter as FfiParam};
|
||||
|
||||
|
|
@ -176,7 +176,13 @@ impl Display for Token {
|
|||
|
||||
impl From<&str> for Token {
|
||||
fn from(value: &str) -> Self {
|
||||
Token::Value(vec![value.to_smolstr()])
|
||||
Token::Value(vec![SmolStr::new(value)])
|
||||
}
|
||||
}
|
||||
|
||||
impl<const L: usize> From<[&str; L]> for Token {
|
||||
fn from(value: [&str; L]) -> Self {
|
||||
Token::Value(value.into_iter().map(SmolStr::from).collect::<Vec<_>>())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -191,20 +197,3 @@ impl<P: Parameter + 'static> From<(ParamName, P)> for Token {
|
|||
Token::Parameter(value.0, Arc::new(value.1))
|
||||
}
|
||||
}
|
||||
|
||||
impl<const L: usize, T: Into<Token>> From<[T; L]> for Token {
|
||||
fn from(value: [T; L]) -> Self {
|
||||
let tokens = value.into_iter().map(|s| s.into()).collect::<Vec<_>>();
|
||||
if tokens.iter().all(|t| matches!(t, Token::Value(_))) {
|
||||
let values = tokens
|
||||
.into_iter()
|
||||
.flat_map(|t| match t {
|
||||
Token::Value(v) => v,
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
return Token::Value(values);
|
||||
}
|
||||
Token::Any(tokens)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue