diff options
| author | Ubuntu <github@matdoes.dev> | 2022-01-13 00:43:09 +0000 |
|---|---|---|
| committer | Ubuntu <github@matdoes.dev> | 2022-01-13 00:43:09 +0000 |
| commit | eb111be1f107696939b994f5de6e060cf972a732 (patch) | |
| tree | 055deab4179088c5e91a179bfe465a7859c45ab6 /azalea-brigadier/src/builder/argument_builder.rs | |
| parent | 270507736af57aae6801dc9eb3c3132139d0d07b (diff) | |
| download | azalea-drasl-eb111be1f107696939b994f5de6e060cf972a732.tar.xz | |
a
Diffstat (limited to 'azalea-brigadier/src/builder/argument_builder.rs')
| -rw-r--r-- | azalea-brigadier/src/builder/argument_builder.rs | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/azalea-brigadier/src/builder/argument_builder.rs b/azalea-brigadier/src/builder/argument_builder.rs index 0360b05a..6355456a 100644 --- a/azalea-brigadier/src/builder/argument_builder.rs +++ b/azalea-brigadier/src/builder/argument_builder.rs @@ -1,33 +1,32 @@ use crate::{ - arguments::argument_type::{ArgumentType, Types}, + arguments::argument_type::ArgumentType, command::Command, redirect_modifier::RedirectModifier, single_redirect_modifier::SingleRedirectModifier, tree::{command_node::CommandNode, root_command_node::RootCommandNode}, }; -pub struct BaseArgumentBuilder<'a, S, T> +pub struct BaseArgumentBuilder<'a, S> where S: Sized, - T: Sized + ArgumentType<dyn Types>, { - arguments: RootCommandNode<'a, S, T>, - command: Option<&'a dyn Command<S, T>>, + arguments: RootCommandNode<'a, S>, + command: Option<&'a dyn Command<S>>, requirement: &'a dyn Fn(&S) -> bool, - target: Option<&'a dyn CommandNode<S, T>>, - modifier: Option<&'a dyn RedirectModifier<S, T>>, + target: Option<&'a dyn CommandNode<S>>, + modifier: Option<&'a dyn RedirectModifier<S>>, forks: bool, } -pub trait ArgumentBuilder<S, T> { - fn build(self) -> dyn CommandNode<S, T>; -} - -impl<S, T> BaseArgumentBuilder<'_, S, T> +pub trait ArgumentBuilder<S, T> where - T: ArgumentType<dyn Types>, + T: ArgumentBuilder<S, T>, { - pub fn then(&mut self, command: dyn CommandNode<S, T>) -> Result<&mut T, String> { + fn build(self) -> dyn CommandNode<S>; +} + +impl<S> BaseArgumentBuilder<'_, S> { + pub fn then(&mut self, command: dyn CommandNode<S>) -> Result<&mut Self, String> { if self.target.is_some() { return Err("Cannot add children to a redirected node".to_string()); } @@ -35,20 +34,20 @@ where Ok(self) } - pub fn arguments(&self) -> &Vec<&dyn CommandNode<S, T>> { + pub fn arguments(&self) -> &Vec<&dyn CommandNode<S>> { &self.arguments.get_children() } - pub fn executes(&mut self, command: dyn Command<S, T>) -> &mut T { + pub fn executes(&mut self, command: dyn Command<S>) -> &mut Self { self.command = command; self } - pub fn command(&self) -> dyn Command<S, T> { + pub fn command(&self) -> dyn Command<S> { self.command } - pub fn requires(&mut self, requirement: &dyn Fn(&S) -> bool) -> &mut T { + pub fn requires(&mut self, requirement: &dyn Fn(&S) -> bool) -> &mut Self { self.requirement = requirement; self } @@ -57,33 +56,33 @@ where self.requirement } - pub fn redirect(&mut self, target: &dyn CommandNode<S, T>) -> &mut T { + pub fn redirect(&mut self, target: &dyn CommandNode<S>) -> &mut Self { self.forward(target, None, false) } pub fn redirect_modifier( &mut self, - target: &dyn CommandNode<S, T>, - modifier: &dyn SingleRedirectModifier<S, T>, - ) -> &mut T { + target: &dyn CommandNode<S>, + modifier: &dyn SingleRedirectModifier<S>, + ) -> &mut Self { // forward(target, modifier == null ? null : o -> Collections.singleton(modifier.apply(o)), false); self.forward(target, modifier.map(|m| |o| vec![m.apply(o)]), false) } pub fn fork( &mut self, - target: &dyn CommandNode<S, T>, - modifier: &dyn RedirectModifier<S, T>, - ) -> &mut T { + target: &dyn CommandNode<S>, + modifier: &dyn RedirectModifier<S>, + ) -> &mut Self { self.forward(target, Some(modifier), true) } pub fn forward( &mut self, - target: &dyn CommandNode<S, T>, - modifier: Option<&dyn RedirectModifier<S, T>>, + target: &dyn CommandNode<S>, + modifier: Option<&dyn RedirectModifier<S>>, fork: bool, - ) -> Result<&mut T, String> { + ) -> Result<&mut Self, String> { if !self.arguments.get_children().is_empty() { return Err("Cannot forward a node with children".to_string()); } @@ -93,11 +92,11 @@ where Ok(self) } - pub fn get_redirect(&self) -> Option<&dyn CommandNode<S, T>> { + pub fn get_redirect(&self) -> Option<&dyn CommandNode<S>> { self.target.as_ref() } - pub fn get_redirect_modifier(&self) -> Option<&dyn RedirectModifier<S, T>> { + pub fn get_redirect_modifier(&self) -> Option<&dyn RedirectModifier<S>> { self.modifier.as_ref() } |
