mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-07 14:27:54 +00:00
refactor(command_parser): combine TokenMatchError and TokenMatchedValue into a single result type
This commit is contained in:
parent
92276a720e
commit
58d493ac0a
3 changed files with 70 additions and 84 deletions
|
|
@ -2,7 +2,7 @@ use std::{fmt::Debug, str::FromStr};
|
|||
|
||||
use smol_str::SmolStr;
|
||||
|
||||
use crate::token::Token;
|
||||
use crate::token::{Token, TokenMatchResult};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ParameterValue {
|
||||
|
|
@ -192,8 +192,12 @@ impl FromStr for Toggle {
|
|||
type Err = SmolStr;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let matches_self =
|
||||
|toggle: &Self| matches!(Token::from(*toggle).try_match(Some(s)), Some(Ok(None)));
|
||||
let matches_self = |toggle: &Self| {
|
||||
matches!(
|
||||
Token::from(*toggle).try_match(Some(s)),
|
||||
Some(TokenMatchResult::MatchedValue)
|
||||
)
|
||||
};
|
||||
[Self::On, Self::Off]
|
||||
.into_iter()
|
||||
.find(matches_self)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue