aboutsummaryrefslogtreecommitdiff
path: root/azalea-brigadier/src/context/command_context.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2026-05-06 18:38:23 -0545
committermat <git@matdoes.dev>2026-05-07 08:05:58 -1200
commitcabc8b60a729ba17f5b75f7a7956c6d1ddcc8919 (patch)
tree237fd12a9768fe7431ce42dfbdde60f4c7850e06 /azalea-brigadier/src/context/command_context.rs
parent9ffd0e80bbb3feace231553d6539124585b03e3c (diff)
downloadazalea-drasl-cabc8b60a729ba17f5b75f7a7956c6d1ddcc8919.tar.xz
azalea-brigadier now allows commands to return a Result
Diffstat (limited to 'azalea-brigadier/src/context/command_context.rs')
-rw-r--r--azalea-brigadier/src/context/command_context.rs30
1 files changed, 15 insertions, 15 deletions
diff --git a/azalea-brigadier/src/context/command_context.rs b/azalea-brigadier/src/context/command_context.rs
index a9959895..0139f7e9 100644
--- a/azalea-brigadier/src/context/command_context.rs
+++ b/azalea-brigadier/src/context/command_context.rs
@@ -15,20 +15,20 @@ use crate::{
};
/// A built `CommandContextBuilder`.
-pub struct CommandContext<S> {
+pub struct CommandContext<S, R = i32> {
pub source: Arc<S>,
pub(super) input: String,
pub(super) arguments: HashMap<String, ParsedArgument>,
- pub(super) command: Command<S>,
- pub(super) root_node: Arc<RwLock<CommandNode<S>>>,
- pub(super) nodes: Vec<ParsedCommandNode<S>>,
+ pub(super) command: Command<S, R>,
+ pub(super) root_node: Arc<RwLock<CommandNode<S, R>>>,
+ pub(super) nodes: Vec<ParsedCommandNode<S, R>>,
pub(super) range: StringRange,
- pub(super) child: Option<Rc<CommandContext<S>>>,
- pub(super) modifier: Option<Arc<RedirectModifier<S>>>,
+ pub(super) child: Option<Rc<CommandContext<S, R>>>,
+ pub(super) modifier: Option<Arc<RedirectModifier<S, R>>>,
pub(super) forks: bool,
}
-impl<S> Clone for CommandContext<S> {
+impl<S, R> Clone for CommandContext<S, R> {
fn clone(&self) -> Self {
Self {
source: self.source.clone(),
@@ -45,7 +45,7 @@ impl<S> Clone for CommandContext<S> {
}
}
-impl<S> Debug for CommandContext<S> {
+impl<S, R> Debug for CommandContext<S, R> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("CommandContext")
// .field("source", &self.source)
@@ -62,7 +62,7 @@ impl<S> Debug for CommandContext<S> {
}
}
-impl<S> CommandContext<S> {
+impl<S, R> CommandContext<S, R> {
pub fn copy_for(&self, source: Arc<S>) -> Self {
if Arc::ptr_eq(&source, &self.source) {
// fast path
@@ -83,11 +83,11 @@ impl<S> CommandContext<S> {
}
}
- pub fn child(&self) -> Option<&CommandContext<S>> {
+ pub fn child(&self) -> Option<&CommandContext<S, R>> {
self.child.as_ref().map(|c| c.as_ref())
}
- pub fn last_child(&self) -> &CommandContext<S> {
+ pub fn last_child(&self) -> &CommandContext<S, R> {
let mut result = self;
while let Some(child) = result.child() {
result = child;
@@ -95,7 +95,7 @@ impl<S> CommandContext<S> {
result
}
- pub fn command(&self) -> &Command<S> {
+ pub fn command(&self) -> &Command<S, R> {
&self.command
}
@@ -104,7 +104,7 @@ impl<S> CommandContext<S> {
argument.map(|a| a.result.as_ref())
}
- pub fn redirect_modifier(&self) -> Option<&RedirectModifier<S>> {
+ pub fn redirect_modifier(&self) -> Option<&RedirectModifier<S, R>> {
self.modifier.as_ref().map(|m| m.as_ref())
}
@@ -116,11 +116,11 @@ impl<S> CommandContext<S> {
&self.input
}
- pub fn root_node(&self) -> &Arc<RwLock<CommandNode<S>>> {
+ pub fn root_node(&self) -> &Arc<RwLock<CommandNode<S, R>>> {
&self.root_node
}
- pub fn nodes(&self) -> &[ParsedCommandNode<S>] {
+ pub fn nodes(&self) -> &[ParsedCommandNode<S, R>] {
&self.nodes
}