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 +++++++++++----------- .../src/builder/literal_argument_builder.rs | 4 +- .../src/builder/required_argument_builder.rs | 22 +++++----- 3 files changed, 37 insertions(+), 37 deletions(-) (limited to 'azalea-brigadier/src/builder') 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(), diff --git a/azalea-brigadier/src/builder/literal_argument_builder.rs b/azalea-brigadier/src/builder/literal_argument_builder.rs index 7045b79f..c55fbeed 100644 --- a/azalea-brigadier/src/builder/literal_argument_builder.rs +++ b/azalea-brigadier/src/builder/literal_argument_builder.rs @@ -12,13 +12,13 @@ impl Literal { } } -impl From for ArgumentBuilderType { +impl From for ArgumentBuilderType { fn from(literal: Literal) -> Self { Self::Literal(literal) } } /// Shortcut for creating a new literal builder node. -pub fn literal(value: &str) -> ArgumentBuilder { +pub fn literal(value: &str) -> ArgumentBuilder { ArgumentBuilder::new(ArgumentBuilderType::Literal(Literal::new(value))) } diff --git a/azalea-brigadier/src/builder/required_argument_builder.rs b/azalea-brigadier/src/builder/required_argument_builder.rs index 01bfc0bc..e0822db3 100644 --- a/azalea-brigadier/src/builder/required_argument_builder.rs +++ b/azalea-brigadier/src/builder/required_argument_builder.rs @@ -16,16 +16,16 @@ use crate::{ /// An argument node type. /// /// The `T` type parameter is the type of the argument, which can be anything. -pub struct Argument { +pub struct Argument { pub name: String, parser: Arc, - custom_suggestions: Option + Send + Sync>>, + custom_suggestions: Option + Send + Sync>>, } -impl Argument { +impl Argument { pub fn new( name: &str, parser: Arc, - custom_suggestions: Option + Send + Sync>>, + custom_suggestions: Option + Send + Sync>>, ) -> Self { Self { name: name.to_owned(), @@ -40,7 +40,7 @@ impl Argument { pub fn list_suggestions( &self, - context: CommandContext, + context: CommandContext, builder: SuggestionsBuilder, ) -> Suggestions { if let Some(s) = &self.custom_suggestions { @@ -55,13 +55,13 @@ impl Argument { } } -impl From> for ArgumentBuilderType { - fn from(argument: Argument) -> Self { +impl From> for ArgumentBuilderType { + fn from(argument: Argument) -> Self { Self::Argument(argument) } } -impl Debug for Argument { +impl Debug for Argument { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Argument") .field("name", &self.name) @@ -71,14 +71,14 @@ impl Debug for Argument { } /// Shortcut for creating a new argument builder node. -pub fn argument( +pub fn argument( name: &str, parser: impl ArgumentType + Send + Sync + 'static, -) -> ArgumentBuilder { +) -> ArgumentBuilder { ArgumentBuilder::new(Argument::new(name, Arc::new(parser), None).into()) } -impl Clone for Argument { +impl Clone for Argument { fn clone(&self) -> Self { Self { name: self.name.clone(), -- cgit v1.2.3