aboutsummaryrefslogtreecommitdiff
path: root/examples/example-completion/src/main.rs
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-completion/src/main.rs
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-completion/src/main.rs')
-rw-r--r--examples/example-completion/src/main.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/examples/example-completion/src/main.rs b/examples/example-completion/src/main.rs
index 0c64d03..0159807 100644
--- a/examples/example-completion/src/main.rs
+++ b/examples/example-completion/src/main.rs
@@ -45,6 +45,7 @@
//! ```
use mingling::{macros::suggest, prelude::*, ShellContext, Suggest};
+use std::io::Write;
fn main() {
let mut program = ThisProgram::new();
@@ -118,13 +119,15 @@ fn handle_greet(args: EntryGreet) -> Next {
/// Renders the greeting with the result name and repeat count.
#[renderer]
-fn render_name(result: ResultName) {
+fn render_name(result: ResultName) -> RenderResult {
let (repeat, name) = result.inner;
+ let mut render_result = RenderResult::new();
let mut parts = Vec::with_capacity(repeat as usize);
for _ in 0..repeat {
parts.push(name.clone());
}
- r_println!("Hello, {}!", parts.join(", "));
+ writeln!(render_result, "Hello, {}!", parts.join(", ")).ok();
+ render_result
}
gen_program!();