From eb111be1f107696939b994f5de6e060cf972a732 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 13 Jan 2022 00:43:09 +0000 Subject: a --- azalea-brigadier/src/tree/argument_command_node.rs | 48 +++++++++------------- 1 file changed, 20 insertions(+), 28 deletions(-) (limited to 'azalea-brigadier/src/tree/argument_command_node.rs') diff --git a/azalea-brigadier/src/tree/argument_command_node.rs b/azalea-brigadier/src/tree/argument_command_node.rs index 3fc1bb50..fb9a75fa 100644 --- a/azalea-brigadier/src/tree/argument_command_node.rs +++ b/azalea-brigadier/src/tree/argument_command_node.rs @@ -1,7 +1,10 @@ -use std::fmt::{Display, Formatter}; +use std::{ + any::Any, + fmt::{Display, Formatter}, +}; use crate::{ - arguments::argument_type::{ArgumentType, Types}, + arguments::argument_type::ArgumentType, builder::required_argument_builder::RequiredArgumentBuilder, context::{ command_context::CommandContext, command_context_builder::CommandContextBuilder, @@ -22,35 +25,27 @@ const USAGE_ARGUMENT_OPEN: &str = "<"; const USAGE_ARGUMENT_CLOSE: &str = ">"; #[derive(Clone)] -pub struct ArgumentCommandNode<'a, S, T> -where - // each argument command node has its own different type - T: ArgumentType, -{ +pub struct ArgumentCommandNode<'a, S> { name: String, - type_: &'a T, - custom_suggestions: Option<&'a dyn SuggestionProvider>, - // custom_suggestions: &'a dyn SuggestionProvider, + type_: Box>, + custom_suggestions: Option<&'a dyn SuggestionProvider>, + // custom_suggestions: &'a dyn SuggestionProvider, // Since Rust doesn't have extending, we put the struct this is extending as the "base" field - pub base: BaseCommandNode<'a, S, T>, + pub base: BaseCommandNode<'a, S>, } -impl ArgumentCommandNode<'_, S, T> -where - T: ArgumentType, -{ - fn get_type(&self) -> &T { - &self.type_ +impl ArgumentCommandNode<'_, S> { + fn get_type(&self) -> &dyn ArgumentType { + self.type_ } - fn custom_suggestions(&self) -> Option<&dyn SuggestionProvider> { + fn custom_suggestions(&self) -> Option<&dyn SuggestionProvider> { self.custom_suggestions } } -impl<'a, S, T> CommandNode for ArgumentCommandNode<'a, S, T> +impl<'a, S> CommandNode for ArgumentCommandNode<'a, S> where - T: ArgumentType + Clone, S: Clone, { fn name(&self) -> &str { @@ -60,11 +55,11 @@ where fn parse( &self, reader: &mut StringReader, - context_builder: CommandContextBuilder, + context_builder: CommandContextBuilder, ) -> Result<(), CommandSyntaxException> { // final int start = reader.getCursor(); // final T result = type.parse(reader); - // final ParsedArgument parsed = new ParsedArgument<>(start, reader.getCursor(), result); + // final ParsedArgument parsed = new ParsedArgument<>(start, reader.getCursor(), result); // contextBuilder.withArgument(name, parsed); // contextBuilder.withNode(this, parsed.getRange()); @@ -81,7 +76,7 @@ where fn list_suggestions( &self, - context: CommandContext, + context: CommandContext, builder: &mut SuggestionsBuilder, ) -> Result { if self.custom_suggestions.is_none() { @@ -105,7 +100,7 @@ where USAGE_ARGUMENT_OPEN + self.name + USAGE_ARGUMENT_CLOSE } - fn create_builder(&self) -> RequiredArgumentBuilder { + fn create_builder(&self) -> RequiredArgumentBuilder { let builder = RequiredArgumentBuilder::argument(&self.name, &self.type_); builder.requires(self.base.get_requirement()); builder.forward( @@ -125,10 +120,7 @@ where } } -impl Display for ArgumentCommandNode<'_, S, T> -where - T: ArgumentType, -{ +impl Display for ArgumentCommandNode<'_, S> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "", self.name, self.type_) } -- cgit v1.2.3