From cabc8b60a729ba17f5b75f7a7956c6d1ddcc8919 Mon Sep 17 00:00:00 2001 From: mat Date: Wed, 6 May 2026 18:38:23 -0545 Subject: azalea-brigadier now allows commands to return a Result --- .../src/context/command_context_builder.rs | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 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 a3819246..e3b09fc1 100644 --- a/azalea-brigadier/src/context/command_context_builder.rs +++ b/azalea-brigadier/src/context/command_context_builder.rs @@ -17,20 +17,20 @@ use crate::{ tree::{Command, CommandNode}, }; -pub struct CommandContextBuilder<'a, S> { +pub struct CommandContextBuilder<'a, S, R> { pub arguments: HashMap, - pub root: Arc>>, - pub nodes: Vec>, - pub dispatcher: &'a CommandDispatcher, + pub root: Arc>>, + pub nodes: Vec>, + pub dispatcher: &'a CommandDispatcher, pub source: Arc, - pub command: Command, - pub child: Option>>, + pub command: Command, + pub child: Option>>, pub range: StringRange, - pub modifier: Option>>, + pub modifier: Option>>, pub forks: bool, } -impl Clone for CommandContextBuilder<'_, S> { +impl Clone for CommandContextBuilder<'_, S, R> { fn clone(&self) -> Self { Self { arguments: self.arguments.clone(), @@ -47,11 +47,11 @@ impl Clone for CommandContextBuilder<'_, S> { } } -impl<'a, S> CommandContextBuilder<'a, S> { +impl<'a, S, R> CommandContextBuilder<'a, S, R> { pub fn new( - dispatcher: &'a CommandDispatcher, + dispatcher: &'a CommandDispatcher, source: Arc, - root_node: Arc>>, + root_node: Arc>>, start: usize, ) -> Self { Self { @@ -68,11 +68,11 @@ impl<'a, S> CommandContextBuilder<'a, S> { } } - pub fn with_command(&mut self, command: &Command) -> &Self { + pub fn with_command(&mut self, command: &Command) -> &Self { self.command.clone_from(command); self } - pub fn with_child(&mut self, child: Rc>) -> &Self { + pub fn with_child(&mut self, child: Rc>) -> &Self { self.child = Some(child); self } @@ -80,7 +80,7 @@ impl<'a, S> CommandContextBuilder<'a, S> { self.arguments.insert(name.to_owned(), argument); self } - pub fn with_node(&mut self, node: Arc>>, range: StringRange) -> &Self { + pub fn with_node(&mut self, node: Arc>>, range: StringRange) -> &Self { self.nodes.push(ParsedCommandNode { node: node.clone(), range, @@ -91,7 +91,7 @@ impl<'a, S> CommandContextBuilder<'a, S> { self } - pub fn build(&self, input: &str) -> CommandContext { + pub fn build(&self, input: &str) -> CommandContext { CommandContext { arguments: self.arguments.clone(), root_node: self.root.clone(), @@ -106,7 +106,7 @@ impl<'a, S> CommandContextBuilder<'a, S> { } } - pub fn find_suggestion_context(&self, cursor: usize) -> SuggestionContext { + pub fn find_suggestion_context(&self, cursor: usize) -> SuggestionContext { if self.range.start() > cursor { panic!("Can't find node before cursor"); } @@ -144,7 +144,7 @@ impl<'a, S> CommandContextBuilder<'a, S> { } } -impl Debug for CommandContextBuilder<'_, S> { +impl Debug for CommandContextBuilder<'_, S, R> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("CommandContextBuilder") // .field("arguments", &self.arguments) -- cgit v1.2.3