From eb111be1f107696939b994f5de6e060cf972a732 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 13 Jan 2022 00:43:09 +0000 Subject: a --- .../src/context/command_context_builder.rs | 62 ++++++++++------------ 1 file changed, 27 insertions(+), 35 deletions(-) (limited to 'azalea-brigadier/src/context/command_context_builder.rs') diff --git a/azalea-brigadier/src/context/command_context_builder.rs b/azalea-brigadier/src/context/command_context_builder.rs index 639a97ee..95da4064 100644 --- a/azalea-brigadier/src/context/command_context_builder.rs +++ b/azalea-brigadier/src/context/command_context_builder.rs @@ -1,10 +1,8 @@ -use std::collections::HashMap; +use std::{any::Any, collections::HashMap}; use crate::{ - arguments::argument_type::{ArgumentType, Types}, - command::Command, - command_dispatcher::CommandDispatcher, - redirect_modifier::RedirectModifier, + arguments::argument_type::ArgumentType, command::Command, + command_dispatcher::CommandDispatcher, redirect_modifier::RedirectModifier, tree::command_node::CommandNode, }; @@ -27,19 +25,16 @@ use super::{ // private boolean forks; #[derive(Clone)] -pub struct CommandContextBuilder<'a, S, T> -where - T: ArgumentType, -{ - arguments: HashMap>, - root_node: &'a dyn CommandNode, - nodes: Vec>, - dispatcher: CommandDispatcher<'a, S, T>, +pub struct CommandContextBuilder<'a, S> { + arguments: HashMap>>, + root_node: &'a dyn CommandNode, + nodes: Vec>, + dispatcher: CommandDispatcher<'a, S>, source: S, - command: Box>, - child: Option>, + command: Box>, + child: Option>, range: StringRange, - modifier: Option>>, + modifier: Option>>, forks: bool, } @@ -50,14 +45,11 @@ where // this.range = StringRange.at(start); // } -impl CommandContextBuilder<'_, S, T> -where - T: ArgumentType, -{ +impl CommandContextBuilder<'_, S> { pub fn new( - dispatcher: CommandDispatcher, + dispatcher: CommandDispatcher, source: S, - root_node: dyn CommandNode, + root_node: dyn CommandNode, start: usize, ) -> Self { Self { @@ -78,25 +70,25 @@ where &self.source } - pub fn root_node(&self) -> &dyn CommandNode { + pub fn root_node(&self) -> &dyn CommandNode { &self.root_node } - pub fn with_argument(mut self, name: String, argument: ParsedArgument) -> Self { + pub fn with_argument(mut self, name: String, argument: ParsedArgument>) -> Self { self.arguments.insert(name, argument); self } - pub fn arguments(&self) -> &HashMap> { + pub fn arguments(&self) -> &HashMap>> { &self.arguments } - pub fn with_command(mut self, command: &dyn Command) -> Self { + pub fn with_command(mut self, command: &dyn Command) -> Self { self.command = command; self } - pub fn with_node(mut self, node: dyn CommandNode, range: StringRange) -> Self { + pub fn with_node(mut self, node: dyn CommandNode, range: StringRange) -> Self { self.nodes.push(ParsedCommandNode::new(node, range)); self.range = StringRange::encompassing(&self.range, &range); self.modifier = node.redirect_modifier(); @@ -104,16 +96,16 @@ where self } - pub fn with_child(mut self, child: CommandContextBuilder) -> Self { + pub fn with_child(mut self, child: CommandContextBuilder) -> Self { self.child = Some(child); self } - pub fn child(&self) -> Option<&CommandContextBuilder> { + pub fn child(&self) -> Option<&CommandContextBuilder> { self.child.as_ref() } - pub fn last_child(&self) -> Option<&CommandContextBuilder> { + pub fn last_child(&self) -> Option<&CommandContextBuilder> { let mut result = self; while let Some(child) = result.child() { result = child; @@ -121,15 +113,15 @@ where Some(result) } - pub fn command(&self) -> &dyn Command { + pub fn command(&self) -> &dyn Command { &*self.command } - pub fn nodes(&self) -> &Vec> { + pub fn nodes(&self) -> &Vec> { &self.nodes } - pub fn build(self, input: &str) -> CommandContext { + pub fn build(self, input: &str) -> CommandContext { CommandContext { source: self.source, input, @@ -144,7 +136,7 @@ where } } - pub fn dispatcher(&self) -> &CommandDispatcher { + pub fn dispatcher(&self) -> &CommandDispatcher { &self.dispatcher } @@ -152,7 +144,7 @@ where &self.range } - pub fn find_suggestion_context(&self, cursor: i32) -> Result, String> { + pub fn find_suggestion_context(&self, cursor: i32) -> Result, String> { if self.range.start() <= cursor { if self.range.end() < cursor { if let Some(child) = self.child() { -- cgit v1.2.3