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 --- azalea-brigadier/src/context/command_context.rs | 6 ++++-- .../src/context/command_context_builder.rs | 18 ++++++++++-------- azalea-brigadier/src/context/parsed_command_node.rs | 6 ++++-- 3 files changed, 18 insertions(+), 12 deletions(-) (limited to 'azalea-brigadier/src/context') 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 { @@ -11,7 +13,7 @@ pub struct CommandContext { pub input: String, pub arguments: HashMap, pub command: Command, - pub root_node: Rc>>, + pub root_node: Arc>>, pub nodes: Vec>, pub range: StringRange, pub child: Option>>, 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 } 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 { - pub node: Rc>>, + pub node: Arc>>, pub range: StringRange, } -- cgit v1.2.3