aboutsummaryrefslogtreecommitdiff
path: root/azalea-brigadier/src/context
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-05-05 23:09:57 -0500
committermat <git@matdoes.dev>2023-05-05 23:09:57 -0500
commit12370ab07609bf78baef4ec2302fa4ba44317dae (patch)
tree4fc8eecd79350cd06f52b7d3b5c166a0093fd10f /azalea-brigadier/src/context
parente4176937f0584a6bcc5aba15abb1e2df6ddf588d (diff)
downloadazalea-drasl-12370ab07609bf78baef4ec2302fa4ba44317dae.tar.xz
change some things to be Arc+RwLock in brigadier
Diffstat (limited to 'azalea-brigadier/src/context')
-rwxr-xr-xazalea-brigadier/src/context/command_context.rs6
-rwxr-xr-xazalea-brigadier/src/context/command_context_builder.rs18
-rwxr-xr-xazalea-brigadier/src/context/parsed_command_node.rs6
3 files changed, 18 insertions, 12 deletions
diff --git a/azalea-brigadier/src/context/command_context.rs b/azalea-brigadier/src/context/command_context.rs
index 98609a6e..88af2002 100755
--- a/azalea-brigadier/src/context/command_context.rs
+++ b/azalea-brigadier/src/context/command_context.rs
@@ -1,9 +1,11 @@
+use parking_lot::RwLock;
+
use super::{parsed_command_node::ParsedCommandNode, string_range::StringRange, ParsedArgument};
use crate::{
modifier::RedirectModifier,
tree::{Command, CommandNode},
};
-use std::{any::Any, cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc};
+use std::{any::Any, collections::HashMap, fmt::Debug, rc::Rc, sync::Arc};
/// A built `CommandContextBuilder`.
pub struct CommandContext<S> {
@@ -11,7 +13,7 @@ pub struct CommandContext<S> {
pub input: String,
pub arguments: HashMap<String, ParsedArgument>,
pub command: Command<S>,
- pub root_node: Rc<RefCell<CommandNode<S>>>,
+ pub root_node: Arc<RwLock<CommandNode<S>>>,
pub nodes: Vec<ParsedCommandNode<S>>,
pub range: StringRange,
pub child: Option<Rc<CommandContext<S>>>,
diff --git a/azalea-brigadier/src/context/command_context_builder.rs b/azalea-brigadier/src/context/command_context_builder.rs
index b0677158..54063879 100755
--- a/azalea-brigadier/src/context/command_context_builder.rs
+++ b/azalea-brigadier/src/context/command_context_builder.rs
@@ -1,3 +1,5 @@
+use parking_lot::RwLock;
+
use super::{
command_context::CommandContext, parsed_command_node::ParsedCommandNode,
string_range::StringRange, ParsedArgument,
@@ -7,13 +9,13 @@ use crate::{
modifier::RedirectModifier,
tree::{Command, CommandNode},
};
-use std::{cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc};
+use std::{collections::HashMap, fmt::Debug, rc::Rc, sync::Arc};
pub struct CommandContextBuilder<'a, S> {
pub arguments: HashMap<String, ParsedArgument>,
- pub root: Rc<RefCell<CommandNode<S>>>,
+ pub root: Arc<RwLock<CommandNode<S>>>,
pub nodes: Vec<ParsedCommandNode<S>>,
- pub dispatcher: &'a CommandDispatcher<'a, S>,
+ pub dispatcher: &'a CommandDispatcher<S>,
pub source: Rc<S>,
pub command: Command<S>,
pub child: Option<Rc<CommandContextBuilder<'a, S>>>,
@@ -28,7 +30,7 @@ impl<S> Clone for CommandContextBuilder<'_, S> {
arguments: self.arguments.clone(),
root: self.root.clone(),
nodes: self.nodes.clone(),
- dispatcher: self.dispatcher.clone(),
+ dispatcher: self.dispatcher,
source: self.source.clone(),
command: self.command.clone(),
child: self.child.clone(),
@@ -43,7 +45,7 @@ impl<'a, S> CommandContextBuilder<'a, S> {
pub fn new(
dispatcher: &'a CommandDispatcher<S>,
source: Rc<S>,
- root_node: Rc<RefCell<CommandNode<S>>>,
+ root_node: Arc<RwLock<CommandNode<S>>>,
start: usize,
) -> Self {
Self {
@@ -72,14 +74,14 @@ impl<'a, S> CommandContextBuilder<'a, S> {
self.arguments.insert(name.to_string(), argument);
self
}
- pub fn with_node(&mut self, node: Rc<RefCell<CommandNode<S>>>, range: StringRange) -> &Self {
+ pub fn with_node(&mut self, node: Arc<RwLock<CommandNode<S>>>, range: StringRange) -> &Self {
self.nodes.push(ParsedCommandNode {
node: node.clone(),
range: range.clone(),
});
self.range = StringRange::encompassing(&self.range, &range);
- self.modifier = node.borrow().modifier.clone();
- self.forks = node.borrow().forks;
+ self.modifier = node.read().modifier.clone();
+ self.forks = node.read().forks;
self
}
diff --git a/azalea-brigadier/src/context/parsed_command_node.rs b/azalea-brigadier/src/context/parsed_command_node.rs
index ed49928d..bba5d121 100755
--- a/azalea-brigadier/src/context/parsed_command_node.rs
+++ b/azalea-brigadier/src/context/parsed_command_node.rs
@@ -1,10 +1,12 @@
+use parking_lot::RwLock;
+
use super::string_range::StringRange;
use crate::tree::CommandNode;
-use std::{cell::RefCell, rc::Rc};
+use std::sync::Arc;
#[derive(Debug)]
pub struct ParsedCommandNode<S> {
- pub node: Rc<RefCell<CommandNode<S>>>,
+ pub node: Arc<RwLock<CommandNode<S>>>,
pub range: StringRange,
}