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 --- azalea-brigadier/src/builder/argument_builder.rs | 48 ++++++++++++------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'azalea-brigadier/src/builder/argument_builder.rs') diff --git a/azalea-brigadier/src/builder/argument_builder.rs b/azalea-brigadier/src/builder/argument_builder.rs index 27320eba..7617d08a 100644 --- a/azalea-brigadier/src/builder/argument_builder.rs +++ b/azalea-brigadier/src/builder/argument_builder.rs @@ -14,11 +14,11 @@ use crate::{ }; #[derive(Debug)] -pub enum ArgumentBuilderType { +pub enum ArgumentBuilderType { Literal(Literal), - Argument(Argument), + Argument(Argument), } -impl Clone for ArgumentBuilderType { +impl Clone for ArgumentBuilderType { fn clone(&self) -> Self { match self { ArgumentBuilderType::Literal(literal) => ArgumentBuilderType::Literal(literal.clone()), @@ -30,20 +30,20 @@ impl Clone for ArgumentBuilderType { } /// A node that hasn't yet been built. -pub struct ArgumentBuilder { - arguments: CommandNode, +pub struct ArgumentBuilder { + arguments: CommandNode, - command: Command, + command: Command, requirement: Arc bool + Send + Sync>, - target: Option>>>, + target: Option>>>, forks: bool, - modifier: Option>>, + modifier: Option>>, } /// A node that isn't yet built. -impl ArgumentBuilder { - pub fn new(value: ArgumentBuilderType) -> Self { +impl ArgumentBuilder { + pub fn new(value: ArgumentBuilderType) -> Self { Self { arguments: CommandNode { value, @@ -65,14 +65,14 @@ impl ArgumentBuilder { /// literal("foo").then(literal("bar").executes(|ctx: &CommandContext<()>| 42)) /// # ; /// ``` - pub fn then(self, argument: ArgumentBuilder) -> Self { + pub fn then(self, argument: ArgumentBuilder) -> Self { self.then_built(argument.build()) } /// Add an already built child node to this node. /// /// You should usually use [`Self::then`] instead. - pub fn then_built(mut self, argument: CommandNode) -> Self { + pub fn then_built(mut self, argument: CommandNode) -> Self { self.arguments.add_child(&Arc::new(RwLock::new(argument))); self } @@ -90,9 +90,9 @@ impl ArgumentBuilder { /// ``` pub fn executes(mut self, f: F) -> Self where - F: Fn(&CommandContext) -> i32 + Send + Sync + 'static, + F: Fn(&CommandContext) -> R + Send + Sync + 'static, { - self.command = Some(Arc::new(move |ctx: &CommandContext| Ok(f(ctx)))); + self.command = Some(Arc::new(move |ctx: &CommandContext| Ok(f(ctx)))); self } @@ -100,7 +100,7 @@ impl ArgumentBuilder { /// CommandSyntaxError>`. pub fn executes_result(mut self, f: F) -> Self where - F: Fn(&CommandContext) -> Result + Send + Sync + 'static, + F: Fn(&CommandContext) -> Result + Send + Sync + 'static, { self.command = Some(Arc::new(f)); self @@ -131,22 +131,22 @@ impl ArgumentBuilder { self } - pub fn redirect(self, target: Arc>>) -> Self { + pub fn redirect(self, target: Arc>>) -> Self { self.forward(target, None, false) } pub fn fork( self, - target: Arc>>, - modifier: Arc>, + target: Arc>>, + modifier: Arc>, ) -> Self { self.forward(target, Some(modifier), true) } pub fn forward( mut self, - target: Arc>>, - modifier: Option>>, + target: Arc>>, + modifier: Option>>, fork: bool, ) -> Self { if !self.arguments.children.is_empty() { @@ -158,13 +158,13 @@ impl ArgumentBuilder { self } - pub fn arguments(&self) -> &CommandNode { + pub fn arguments(&self) -> &CommandNode { &self.arguments } /// Manually build this node into a [`CommandNode`]. You probably don't need /// to do this yourself. - pub fn build(self) -> CommandNode { + pub fn build(self) -> CommandNode { let mut result = CommandNode { value: self.arguments.value, command: self.command, @@ -185,7 +185,7 @@ impl ArgumentBuilder { } } -impl Debug for ArgumentBuilder { +impl Debug for ArgumentBuilder { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("ArgumentBuilder") .field("arguments", &self.arguments) @@ -197,7 +197,7 @@ impl Debug for ArgumentBuilder { .finish() } } -impl Clone for ArgumentBuilder { +impl Clone for ArgumentBuilder { fn clone(&self) -> Self { Self { arguments: self.arguments.clone(), -- cgit v1.2.3