summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-02-26 01:11:19 +0800
committer魏曹先生 <1992414357@qq.com>2026-02-26 01:11:19 +0800
commit981d244df444d3dcf48dee558109231da7e6a61b (patch)
treefc91b2f20d89dff8f98c9bef65b5fba329c6577e /src
parente3aeb6a1c9955eee2c396230317e63becd24ec6a (diff)
Change cmd_output! macro to take type before value
Diffstat (limited to 'src')
-rw-r--r--src/cmds/cmd/hexdump.rs2
-rw-r--r--src/cmds/cmd/sheetdump.rs2
-rw-r--r--src/cmds/cmd/status.rs2
-rw-r--r--src/systems/cmd/macros.rs11
4 files changed, 9 insertions, 8 deletions
diff --git a/src/cmds/cmd/hexdump.rs b/src/cmds/cmd/hexdump.rs
index 82f5d45..66022ef 100644
--- a/src/cmds/cmd/hexdump.rs
+++ b/src/cmds/cmd/hexdump.rs
@@ -40,7 +40,7 @@ async fn exec(
collect: Collect,
) -> Result<(Box<dyn std::any::Any + Send + 'static>, TypeId), CmdExecuteError> {
let output = JVHexOutput { data: collect.data };
- cmd_output!(output, JVHexOutput)
+ cmd_output!(JVHexOutput => output)
}
crate::command_template!();
diff --git a/src/cmds/cmd/sheetdump.rs b/src/cmds/cmd/sheetdump.rs
index defb8ff..1945f44 100644
--- a/src/cmds/cmd/sheetdump.rs
+++ b/src/cmds/cmd/sheetdump.rs
@@ -58,7 +58,7 @@ async fn exec(
let result = JVMappingsOutput {
mappings: mappings_vec,
};
- cmd_output!(result, JVMappingsOutput)
+ cmd_output!(JVMappingsOutput => result)
}
crate::command_template!();
diff --git a/src/cmds/cmd/status.rs b/src/cmds/cmd/status.rs
index 5d5f4a3..3ca2a25 100644
--- a/src/cmds/cmd/status.rs
+++ b/src/cmds/cmd/status.rs
@@ -150,7 +150,7 @@ async fn exec(
now_time: collect.now_time,
};
- cmd_output!(output, JVStatusOutput)
+ cmd_output!(JVStatusOutput => output)
}
crate::command_template!();
diff --git a/src/systems/cmd/macros.rs b/src/systems/cmd/macros.rs
index 454ad30..efb14f7 100644
--- a/src/systems/cmd/macros.rs
+++ b/src/systems/cmd/macros.rs
@@ -76,7 +76,7 @@
/// todo!();
///
/// // Use the following method to return results
-/// cmd_output!(output, JVCustomOutput)
+/// cmd_output!(JVCustomOutput => output)
/// }
/// ```
///
@@ -119,7 +119,7 @@
/// collect: Collect,
/// ) -> Result<(Box<dyn std::any::Any + Send + 'static>, TypeId), CmdExecuteError> {
/// todo!();
-/// cmd_output!(output, JVCustomOutput)
+/// cmd_output!(JVCustomOutput => output)
/// }
/// ```
macro_rules! command_template {
@@ -162,10 +162,11 @@ macro_rules! command_template {
#[macro_export]
macro_rules! cmd_output {
- ($v:expr, $t:ty) => {
+ ($t:ty => $v:expr) => {{
+ let checked_value: $t = $v;
Ok((
- Box::new($v) as Box<dyn std::any::Any + Send + 'static>,
+ Box::new(checked_value) as Box<dyn std::any::Any + Send + 'static>,
std::any::TypeId::of::<$t>(),
))
- };
+ }};
}