diff options
| author | mat <git@matdoes.dev> | 2023-05-05 23:23:11 -0500 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2023-05-05 23:23:11 -0500 |
| commit | f825544e2776ab545ff0a9c674b68183120695cb (patch) | |
| tree | a294fa38650e4ce511fc4d6c8b166f13e23ba18e /azalea-brigadier/src/builder | |
| parent | 12370ab07609bf78baef4ec2302fa4ba44317dae (diff) | |
| download | azalea-drasl-f825544e2776ab545ff0a9c674b68183120695cb.tar.xz | |
CommandDispatcher is now Send+Sync
Diffstat (limited to 'azalea-brigadier/src/builder')
| -rwxr-xr-x | azalea-brigadier/src/builder/argument_builder.rs | 20 | ||||
| -rwxr-xr-x | azalea-brigadier/src/builder/required_argument_builder.rs | 13 |
2 files changed, 18 insertions, 15 deletions
diff --git a/azalea-brigadier/src/builder/argument_builder.rs b/azalea-brigadier/src/builder/argument_builder.rs index a1f3d6ae..c6f2146a 100755 --- a/azalea-brigadier/src/builder/argument_builder.rs +++ b/azalea-brigadier/src/builder/argument_builder.rs @@ -7,7 +7,7 @@ use crate::{ }; use super::{literal_argument_builder::Literal, required_argument_builder::Argument}; -use std::{fmt::Debug, rc::Rc, sync::Arc}; +use std::{fmt::Debug, sync::Arc}; #[derive(Debug, Clone)] pub enum ArgumentBuilderType { @@ -20,11 +20,11 @@ pub struct ArgumentBuilder<S> { arguments: CommandNode<S>, command: Command<S>, - requirement: Rc<dyn Fn(Rc<S>) -> bool>, + requirement: Arc<dyn Fn(Arc<S>) -> bool + Send + Sync>, target: Option<Arc<RwLock<CommandNode<S>>>>, forks: bool, - modifier: Option<Rc<RedirectModifier<S>>>, + modifier: Option<Arc<RedirectModifier<S>>>, } /// A node that isn't yet built. @@ -36,7 +36,7 @@ impl<S> ArgumentBuilder<S> { ..Default::default() }, command: None, - requirement: Rc::new(|_| true), + requirement: Arc::new(|_| true), forks: false, modifier: None, target: None, @@ -54,17 +54,17 @@ impl<S> ArgumentBuilder<S> { pub fn executes<F>(mut self, f: F) -> Self where - F: Fn(&CommandContext<S>) -> i32 + 'static, + F: Fn(&CommandContext<S>) -> i32 + Send + Sync + 'static, { - self.command = Some(Rc::new(f)); + self.command = Some(Arc::new(f)); self } pub fn requires<F>(mut self, requirement: F) -> Self where - F: Fn(Rc<S>) -> bool + 'static, + F: Fn(Arc<S>) -> bool + Send + Sync + 'static, { - self.requirement = Rc::new(requirement); + self.requirement = Arc::new(requirement); self } @@ -75,7 +75,7 @@ impl<S> ArgumentBuilder<S> { pub fn fork( self, target: Arc<RwLock<CommandNode<S>>>, - modifier: Rc<RedirectModifier<S>>, + modifier: Arc<RedirectModifier<S>>, ) -> Self { self.forward(target, Some(modifier), true) } @@ -83,7 +83,7 @@ impl<S> ArgumentBuilder<S> { pub fn forward( mut self, target: Arc<RwLock<CommandNode<S>>>, - modifier: Option<Rc<RedirectModifier<S>>>, + modifier: Option<Arc<RedirectModifier<S>>>, fork: bool, ) -> Self { if !self.arguments.children.is_empty() { diff --git a/azalea-brigadier/src/builder/required_argument_builder.rs b/azalea-brigadier/src/builder/required_argument_builder.rs index 9d4d9e0a..0363d204 100755 --- a/azalea-brigadier/src/builder/required_argument_builder.rs +++ b/azalea-brigadier/src/builder/required_argument_builder.rs @@ -2,17 +2,17 @@ use super::argument_builder::{ArgumentBuilder, ArgumentBuilderType}; use crate::{ arguments::ArgumentType, exceptions::CommandSyntaxException, string_reader::StringReader, }; -use std::{any::Any, fmt::Debug, rc::Rc}; +use std::{any::Any, fmt::Debug, rc::Rc, sync::Arc}; /// An argument node type. The `T` type parameter is the type of the argument, /// which can be anything. #[derive(Clone)] pub struct Argument { pub name: String, - parser: Rc<dyn ArgumentType>, + parser: Arc<dyn ArgumentType + Send + Sync>, } impl Argument { - pub fn new(name: &str, parser: Rc<dyn ArgumentType>) -> Self { + pub fn new(name: &str, parser: Arc<dyn ArgumentType + Send + Sync>) -> Self { Self { name: name.to_string(), parser, @@ -40,6 +40,9 @@ impl Debug for Argument { } /// Shortcut for creating a new argument builder node. -pub fn argument<S>(name: &str, parser: impl ArgumentType + 'static) -> ArgumentBuilder<S> { - ArgumentBuilder::new(Argument::new(name, Rc::new(parser)).into()) +pub fn argument<S>( + name: &str, + parser: impl ArgumentType + Send + Sync + 'static, +) -> ArgumentBuilder<S> { + ArgumentBuilder::new(Argument::new(name, Arc::new(parser)).into()) } |
