From 60b129b3a62b66dd389d1775892405fe735b9540 Mon Sep 17 00:00:00 2001 From: mat Date: Mon, 10 Jan 2022 20:29:46 -0600 Subject: progress --- .../src/context/command_context_builder.rs | 56 ++++++++++------------ 1 file changed, 25 insertions(+), 31 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 5766ea9a..878d7692 100644 --- a/azalea-brigadier/src/context/command_context_builder.rs +++ b/azalea-brigadier/src/context/command_context_builder.rs @@ -25,16 +25,16 @@ use super::{ // private boolean forks; #[derive(Clone)] -pub struct CommandContextBuilder { - arguments: HashMap>>, - root_node: dyn CommandNode, - nodes: Vec>, - dispatcher: CommandDispatcher, +pub struct CommandContextBuilder<'a, S, T> { + arguments: HashMap>, + root_node: &'a dyn CommandNode, + nodes: Vec>, + dispatcher: CommandDispatcher<'a, S, T>, source: S, - command: Box>, - child: Option>, + command: Box>, + child: Option>, range: StringRange, - modifier: Option>>, + modifier: Option>>, forks: bool, } @@ -45,15 +45,15 @@ pub struct CommandContextBuilder { // this.range = StringRange.at(start); // } -impl CommandContextBuilder { +impl CommandContextBuilder<'_, S, T> { pub fn new( - dispatcher: CommandDispatcher, + dispatcher: CommandDispatcher, source: S, - root_node: dyn CommandNode, + root_node: dyn CommandNode, start: usize, ) -> Self { Self { - root_node, + root_node: &root_node, dispatcher, source, range: StringRange::at(start), @@ -70,31 +70,25 @@ impl CommandContextBuilder { &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: Box>) -> 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(); @@ -102,16 +96,16 @@ impl CommandContextBuilder { 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; @@ -119,15 +113,15 @@ impl CommandContextBuilder { 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, @@ -142,7 +136,7 @@ impl CommandContextBuilder { } } - pub fn dispatcher(&self) -> &CommandDispatcher { + pub fn dispatcher(&self) -> &CommandDispatcher { &self.dispatcher } @@ -150,7 +144,7 @@ impl CommandContextBuilder { &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