aboutsummaryrefslogtreecommitdiff
path: root/examples/example-custom-pickable
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-custom-pickable
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-custom-pickable')
-rw-r--r--examples/example-custom-pickable/src/main.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/examples/example-custom-pickable/src/main.rs b/examples/example-custom-pickable/src/main.rs
index 015cc62..d203815 100644
--- a/examples/example-custom-pickable/src/main.rs
+++ b/examples/example-custom-pickable/src/main.rs
@@ -15,6 +15,7 @@
//! ```
use mingling::{macros::route, parser::Pickable, prelude::*, Groupped};
+use std::io::Write;
// Define types that can be recognized by Mingling
// ________________________ `Pickable` trait needs to implement Default
@@ -52,14 +53,18 @@ fn handle_connect(prev: EntryConnect) -> Next {
/// Renders the connected address.
#[renderer]
-fn render_address(addr: Address) {
- r_println!("Connected to \"{}\"", addr.to_string());
+pub fn render_address(addr: Address) -> RenderResult {
+ let mut render_result = RenderResult::new();
+ write!(render_result, "Connected to \"{}\"", addr).ok();
+ render_result
}
/// Renders the error message when address parsing fails.
#[renderer]
-fn render_error_parse_address_failed(_: ErrorParseAddressFailed) {
- r_println!("Failed to parse address");
+pub fn render_error_parse_address_failed(_: ErrorParseAddressFailed) -> RenderResult {
+ let mut render_result = RenderResult::new();
+ write!(render_result, "Failed to parse address").ok();
+ render_result
}
gen_program!();