From d68233e0b1ff61d09ab2c4e22a42f3326054539b Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 17 Apr 2022 20:46:43 -0500 Subject: simplify the generic so it's not an Rc --- azalea-brigadier/src/builder/argument_builder.rs | 37 +++++++++++++++++++----- 1 file changed, 30 insertions(+), 7 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 3c9ae3ed..39edfbd3 100644 --- a/azalea-brigadier/src/builder/argument_builder.rs +++ b/azalea-brigadier/src/builder/argument_builder.rs @@ -1,4 +1,7 @@ -use crate::{context::CommandContext, modifier::RedirectModifier, tree::CommandNode}; +use crate::{ + context::CommandContext, exceptions::command_syntax_exception::CommandSyntaxException, + modifier::RedirectModifier, tree::CommandNode, +}; use super::{literal_argument_builder::Literal, required_argument_builder::Argument}; use std::{any::Any, cell::RefCell, fmt::Debug, rc::Rc}; @@ -10,8 +13,7 @@ pub enum ArgumentBuilderType { } /// A node that hasn't yet been built. -#[derive(Clone)] -pub struct ArgumentBuilder { +pub struct ArgumentBuilder { arguments: CommandNode, command: Option) -> i32>>, @@ -19,11 +21,24 @@ pub struct ArgumentBuilder { target: Option>>>, forks: bool, - modifier: Option>>, + modifier: Option>>, +} + +impl Clone for ArgumentBuilder { + fn clone(&self) -> Self { + Self { + arguments: self.arguments.clone(), + command: self.command.clone(), + requirement: self.requirement.clone(), + target: self.target.clone(), + forks: self.forks.clone(), + modifier: self.modifier.clone(), + } + } } /// A node that isn't yet built. -impl ArgumentBuilder { +impl ArgumentBuilder { pub fn new(value: ArgumentBuilderType) -> Self { Self { arguments: CommandNode { @@ -65,10 +80,18 @@ impl ArgumentBuilder { self.forward(target, None, false) } + pub fn fork( + &mut self, + target: Rc>>, + modifier: Rc>, + ) -> Self { + self.forward(target, Some(modifier), true) + } + pub fn forward( &mut self, target: Rc>>, - modifier: Option>>, + modifier: Option>>, fork: bool, ) -> Self { if !self.arguments.children.is_empty() { @@ -99,7 +122,7 @@ impl ArgumentBuilder { } } -impl Debug for ArgumentBuilder { +impl Debug for ArgumentBuilder { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("ArgumentBuilder") .field("arguments", &self.arguments) -- cgit v1.2.3