aboutsummaryrefslogtreecommitdiff
path: root/examples/example-argument-parse
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-11 15:15:12 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-11 15:21:40 +0800
commit95815041fe2817b4b6bdba6b4f332c90320af7bb (patch)
tree224f3479eca9e44caa247132ecab42f8825b167c /examples/example-argument-parse
parent356879cfd6149bdb235b4e02c0f351a4d2246202 (diff)
refactor(examples): migrate renderers to return RenderResult and add
std::io::Write import Replace r_println!/r_print! macro usage across all example renderers with explicit RenderResult construction using std::io::Write, enabling more flexible output handling and reducing reliance on macro-side effects.
Diffstat (limited to 'examples/example-argument-parse')
-rw-r--r--examples/example-argument-parse/src/main.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/examples/example-argument-parse/src/main.rs b/examples/example-argument-parse/src/main.rs
index 4929b7c..59499a2 100644
--- a/examples/example-argument-parse/src/main.rs
+++ b/examples/example-argument-parse/src/main.rs
@@ -19,6 +19,7 @@
//! ```
use mingling::{macros::route, prelude::*};
+use std::io::Write;
dispatcher!("transfer", CMDTransfer => EntryTransfer);
dispatcher!("strict-transfer", CMDStrictTransfer => EntryStrictTransfer);
@@ -71,20 +72,26 @@ fn handle_strict_transfer_parse(args: EntryStrictTransfer) -> Next {
/// Renders the parsed transfer result (file/dir, size, name).
#[renderer]
-fn render_result_file(result: ResultFile) {
+fn render_result_file(result: ResultFile) -> RenderResult {
let (is_dir, size, name) = result.into();
- r_println!(
+ let mut result = RenderResult::new();
+ writeln!(
+ result,
"{}: {} ({})",
if is_dir { "dir" } else { "file" },
name,
size
)
+ .ok();
+ result
}
/// Renders the error when no name is provided.
#[renderer]
-fn render_error_no_name_provided(_: ErrorNoNameProvided) {
- r_println!("Error: name is not provided")
+fn render_error_no_name_provided(_: ErrorNoNameProvided) -> RenderResult {
+ let mut result = RenderResult::new();
+ writeln!(result, "Error: name is not provided").ok();
+ result
}
gen_program!();