diff options
| author | mat <git@matdoes.dev> | 2026-05-06 18:38:23 -0545 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2026-05-07 08:05:58 -1200 |
| commit | cabc8b60a729ba17f5b75f7a7956c6d1ddcc8919 (patch) | |
| tree | 237fd12a9768fe7431ce42dfbdde60f4c7850e06 /azalea-brigadier/src/errors | |
| parent | 9ffd0e80bbb3feace231553d6539124585b03e3c (diff) | |
| download | azalea-drasl-cabc8b60a729ba17f5b75f7a7956c6d1ddcc8919.tar.xz | |
azalea-brigadier now allows commands to return a Result
Diffstat (limited to 'azalea-brigadier/src/errors')
| -rw-r--r-- | azalea-brigadier/src/errors/command_syntax_error.rs | 4 | ||||
| -rw-r--r-- | azalea-brigadier/src/errors/mod.rs | 21 |
2 files changed, 23 insertions, 2 deletions
diff --git a/azalea-brigadier/src/errors/command_syntax_error.rs b/azalea-brigadier/src/errors/command_syntax_error.rs index fd97b050..a29c95ee 100644 --- a/azalea-brigadier/src/errors/command_syntax_error.rs +++ b/azalea-brigadier/src/errors/command_syntax_error.rs @@ -77,8 +77,8 @@ impl CommandSyntaxError { &self.kind } - pub fn input(&self) -> &Option<String> { - &self.input + pub fn input(&self) -> Option<&str> { + self.input.as_deref() } pub fn cursor(&self) -> Option<usize> { diff --git a/azalea-brigadier/src/errors/mod.rs b/azalea-brigadier/src/errors/mod.rs index facebe5e..49d0f956 100644 --- a/azalea-brigadier/src/errors/mod.rs +++ b/azalea-brigadier/src/errors/mod.rs @@ -3,3 +3,24 @@ mod command_syntax_error; pub use builtin_errors::BuiltInError; pub use command_syntax_error::CommandSyntaxError; + +pub trait CommandResultTrait { + fn new(i: i32) -> Self; + fn as_i32(&self) -> Option<i32>; +} +impl CommandResultTrait for i32 { + fn new(i: i32) -> Self { + i + } + fn as_i32(&self) -> Option<i32> { + Some(*self) + } +} +impl<E> CommandResultTrait for Result<i32, E> { + fn new(i: i32) -> Self { + Ok(i) + } + fn as_i32(&self) -> Option<i32> { + self.as_ref().copied().ok() + } +} |
