aboutsummaryrefslogtreecommitdiff
path: root/azalea-brigadier/src/context
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-05-12 23:40:34 -0500
committermat <git@matdoes.dev>2023-05-12 23:40:34 -0500
commit49952dd1507d70cd63305ffbcae4b062dfb4ce68 (patch)
tree1b3e5bbd757634048988b9c8d96d5fb97f669427 /azalea-brigadier/src/context
parent657c073eab0f09d873bde21d5cdeb13a1bebb71b (diff)
parent2057877eba5f6f13ba6863b48a9cdd44910a44f8 (diff)
downloadazalea-drasl-49952dd1507d70cd63305ffbcae4b062dfb4ce68.tar.xz
Merge branch 'main' into 1.20
Diffstat (limited to 'azalea-brigadier/src/context')
-rwxr-xr-xazalea-brigadier/src/context/command_context.rs16
-rwxr-xr-xazalea-brigadier/src/context/command_context_builder.rs40
-rwxr-xr-xazalea-brigadier/src/context/parsed_command_node.rs6
3 files changed, 34 insertions, 28 deletions
diff --git a/azalea-brigadier/src/context/command_context.rs b/azalea-brigadier/src/context/command_context.rs
index 98609a6e..1734bb05 100755
--- a/azalea-brigadier/src/context/command_context.rs
+++ b/azalea-brigadier/src/context/command_context.rs
@@ -1,21 +1,23 @@
+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> {
- pub source: Rc<S>,
+ pub source: Arc<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>>>,
- pub modifier: Option<Rc<RedirectModifier<S>>>,
+ pub child: Option<Arc<CommandContext<S>>>,
+ pub modifier: Option<Arc<RedirectModifier<S>>>,
pub forks: bool,
}
@@ -54,8 +56,8 @@ impl<S> Debug for CommandContext<S> {
}
impl<S> CommandContext<S> {
- pub fn copy_for(&self, source: Rc<S>) -> Self {
- if Rc::ptr_eq(&source, &self.source) {
+ pub fn copy_for(&self, source: Arc<S>) -> Self {
+ if Arc::ptr_eq(&source, &self.source) {
return self.clone();
}
CommandContext {
diff --git a/azalea-brigadier/src/context/command_context_builder.rs b/azalea-brigadier/src/context/command_context_builder.rs
index 7516ab9e..78088941 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,28 +9,28 @@ use crate::{
modifier::RedirectModifier,
tree::{Command, CommandNode},
};
-use std::{cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc};
+use std::{collections::HashMap, fmt::Debug, sync::Arc};
-pub struct CommandContextBuilder<S> {
+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: Rc<CommandDispatcher<S>>,
- pub source: Rc<S>,
+ pub dispatcher: &'a CommandDispatcher<S>,
+ pub source: Arc<S>,
pub command: Command<S>,
- pub child: Option<Rc<CommandContextBuilder<S>>>,
+ pub child: Option<Arc<CommandContextBuilder<'a, S>>>,
pub range: StringRange,
- pub modifier: Option<Rc<RedirectModifier<S>>>,
+ pub modifier: Option<Arc<RedirectModifier<S>>>,
pub forks: bool,
}
-impl<S> Clone for CommandContextBuilder<S> {
+impl<S> Clone for CommandContextBuilder<'_, S> {
fn clone(&self) -> Self {
Self {
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(),
@@ -39,11 +41,11 @@ impl<S> Clone for CommandContextBuilder<S> {
}
}
-impl<S> CommandContextBuilder<S> {
+impl<'a, S> CommandContextBuilder<'a, S> {
pub fn new(
- dispatcher: Rc<CommandDispatcher<S>>,
- source: Rc<S>,
- root_node: Rc<RefCell<CommandNode<S>>>,
+ dispatcher: &'a CommandDispatcher<S>,
+ source: Arc<S>,
+ root_node: Arc<RwLock<CommandNode<S>>>,
start: usize,
) -> Self {
Self {
@@ -64,7 +66,7 @@ impl<S> CommandContextBuilder<S> {
self.command = command.clone();
self
}
- pub fn with_child(&mut self, child: Rc<CommandContextBuilder<S>>) -> &Self {
+ pub fn with_child(&mut self, child: Arc<CommandContextBuilder<'a, S>>) -> &Self {
self.child = Some(child);
self
}
@@ -72,14 +74,14 @@ impl<S> CommandContextBuilder<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
}
@@ -90,7 +92,7 @@ impl<S> CommandContextBuilder<S> {
nodes: self.nodes.clone(),
source: self.source.clone(),
command: self.command.clone(),
- child: self.child.clone().map(|c| Rc::new(c.build(input))),
+ child: self.child.clone().map(|c| Arc::new(c.build(input))),
range: self.range.clone(),
forks: self.forks,
modifier: self.modifier.clone(),
@@ -99,7 +101,7 @@ impl<S> CommandContextBuilder<S> {
}
}
-impl<S> Debug for CommandContextBuilder<S> {
+impl<S> Debug for CommandContextBuilder<'_, S> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CommandContextBuilder")
// .field("arguments", &self.arguments)
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,
}