aboutsummaryrefslogtreecommitdiff
path: root/azalea-brigadier/src/tree/argument_command_node.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-01-11 00:01:47 -0600
committermat <github@matdoes.dev>2022-01-11 00:01:47 -0600
commitcc4fe62fc82842e0bde628437a45d55c6a82f1f3 (patch)
tree9248cb03406681f81d6d29a0878220fbe1e836e2 /azalea-brigadier/src/tree/argument_command_node.rs
parent60b129b3a62b66dd389d1775892405fe735b9540 (diff)
downloadazalea-drasl-cc4fe62fc82842e0bde628437a45d55c6a82f1f3.tar.xz
adfsfasdfaSDQAWERTERYTUYghyubnjnrdfxcv etgvbhy0ujn-
Diffstat (limited to 'azalea-brigadier/src/tree/argument_command_node.rs')
-rw-r--r--azalea-brigadier/src/tree/argument_command_node.rs23
1 files changed, 14 insertions, 9 deletions
diff --git a/azalea-brigadier/src/tree/argument_command_node.rs b/azalea-brigadier/src/tree/argument_command_node.rs
index 4d38b41f..647b6c35 100644
--- a/azalea-brigadier/src/tree/argument_command_node.rs
+++ b/azalea-brigadier/src/tree/argument_command_node.rs
@@ -1,13 +1,14 @@
use std::fmt::{Display, Formatter};
use crate::{
- arguments::argument_type::ArgumentType,
+ arguments::argument_type::{ArgumentType, Types},
builder::required_argument_builder::RequiredArgumentBuilder,
context::{
command_context::CommandContext, command_context_builder::CommandContextBuilder,
parsed_argument::ParsedArgument,
},
exceptions::command_syntax_exception::CommandSyntaxException,
+ immutable_string_reader::ImmutableStringReader,
string_reader::StringReader,
suggestion::{
suggestion_provider::SuggestionProvider, suggestions::Suggestions,
@@ -20,11 +21,15 @@ use super::command_node::{BaseCommandNode, CommandNode};
const USAGE_ARGUMENT_OPEN: &str = "<";
const USAGE_ARGUMENT_CLOSE: &str = ">";
-#[derive(Hash, PartialEq, Eq, Debug, Clone)]
-pub struct ArgumentCommandNode<'a, S, T> {
+pub struct ArgumentCommandNode<'a, S, T>
+where
+ // each argument command node has its own different type
+ T: ArgumentType<dyn Types>,
+{
name: String,
type_: &'a T,
- custom_suggestions: &'a dyn SuggestionProvider<S, T>,
+ custom_suggestions: Option<&'a dyn SuggestionProvider<S, T>>,
+ // custom_suggestions: &'a dyn SuggestionProvider<S, T>,
// Since Rust doesn't have extending, we put the struct this is extending as the "base" field
pub base: BaseCommandNode<'a, S, T>,
}
@@ -34,12 +39,12 @@ impl<S, T> ArgumentCommandNode<'_, S, T> {
&self.type_
}
- fn custom_suggestions(&self) -> &dyn SuggestionProvider<S, T> {
- &self.custom_suggestions
+ fn custom_suggestions(&self) -> Option<&dyn SuggestionProvider<S, T>> {
+ self.custom_suggestions
}
}
-impl<S, T> CommandNode<S, T> for ArgumentCommandNode<'_, S, T> {
+impl<'a, S, T> CommandNode<S, T> for ArgumentCommandNode<'a, S, T> {
fn name(&self) -> &str {
&self.name
}
@@ -56,7 +61,7 @@ impl<S, T> CommandNode<S, T> for ArgumentCommandNode<'_, S, T> {
// contextBuilder.withArgument(name, parsed);
// contextBuilder.withNode(this, parsed.getRange());
- let start = reader.get_cursor();
+ let start = reader.cursor();
let result = self.get_type().parse(reader)?;
let parsed = ParsedArgument::new(start, reader.get_cursor(), result);
@@ -112,7 +117,7 @@ impl<S, T> CommandNode<S, T> for ArgumentCommandNode<'_, S, T> {
}
}
-impl Display for ArgumentCommandNode<'_, String, String> {
+impl Display for ArgumentCommandNode<'_, (), (), ()> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "<argument {}: {}>", self.name, self.type_)
}