From 12370ab07609bf78baef4ec2302fa4ba44317dae Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 5 May 2023 23:09:57 -0500 Subject: change some things to be Arc+RwLock in brigadier --- .../src/context/command_context_builder.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'azalea-brigadier/src/context/command_context_builder.rs') 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, - pub root: Rc>>, + pub root: Arc>>, pub nodes: Vec>, - pub dispatcher: &'a CommandDispatcher<'a, S>, + pub dispatcher: &'a CommandDispatcher, pub source: Rc, pub command: Command, pub child: Option>>, @@ -28,7 +30,7 @@ impl 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, source: Rc, - root_node: Rc>>, + root_node: Arc>>, 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>>, range: StringRange) -> &Self { + pub fn with_node(&mut self, node: Arc>>, 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 } -- cgit v1.2.3