From 270507736af57aae6801dc9eb3c3132139d0d07b Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 12 Jan 2022 00:40:43 +0000 Subject: a --- azalea-brigadier/src/tree/command_node.rs | 59 ++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 8 deletions(-) (limited to 'azalea-brigadier/src/tree/command_node.rs') diff --git a/azalea-brigadier/src/tree/command_node.rs b/azalea-brigadier/src/tree/command_node.rs index 8e262f0b..f3be1597 100644 --- a/azalea-brigadier/src/tree/command_node.rs +++ b/azalea-brigadier/src/tree/command_node.rs @@ -1,7 +1,6 @@ -use std::collections::HashMap; - +use super::{argument_command_node::ArgumentCommandNode, literal_command_node::LiteralCommandNode}; use crate::{ - arguments::argument_type::ArgumentType, + arguments::argument_type::{ArgumentType, Types}, builder::argument_builder::ArgumentBuilder, command::Command, context::{command_context::CommandContext, command_context_builder::CommandContextBuilder}, @@ -10,10 +9,14 @@ use crate::{ string_reader::StringReader, suggestion::{suggestions::Suggestions, suggestions_builder::SuggestionsBuilder}, }; +use dyn_clonable::*; +use std::{collections::HashMap, fmt::Debug}; -use super::{argument_command_node::ArgumentCommandNode, literal_command_node::LiteralCommandNode}; - -pub struct BaseCommandNode<'a, S, T> { +#[derive(Default)] +pub struct BaseCommandNode<'a, S, T> +where + T: ArgumentType, +{ children: HashMap>, literals: HashMap>, arguments: HashMap>, @@ -24,9 +27,49 @@ pub struct BaseCommandNode<'a, S, T> { command: Option<&'a dyn Command>, } -impl BaseCommandNode<'_, S, T> {} +impl BaseCommandNode<'_, S, T> where T: ArgumentType {} + +impl Clone for BaseCommandNode<'_, S, T> +where + T: ArgumentType, +{ + fn clone(&self) -> Self { + Self { + children: self.children.clone(), + literals: self.literals.clone(), + arguments: self.arguments.clone(), + requirement: self.requirement.clone(), + redirect: self.redirect.clone(), + modifier: self.modifier.clone(), + forks: self.forks.clone(), + command: self.command.clone(), + } + } +} + +impl Debug for BaseCommandNode<'_, S, T> +where + T: ArgumentType, +{ + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("BaseCommandNode") + .field("children", &self.children) + .field("literals", &self.literals) + .field("arguments", &self.arguments) + .field("requirement", &self.requirement) + .field("redirect", &self.redirect) + .field("modifier", &self.modifier) + .field("forks", &self.forks) + .field("command", &self.command) + .finish() + } +} -pub trait CommandNode { +#[clonable] +pub trait CommandNode: Clone +where + T: ArgumentType, +{ fn name(&self) -> &str; fn usage_text(&self) -> &str; fn parse( -- cgit v1.2.3