aboutsummaryrefslogtreecommitdiff
path: root/examples/example-pack-err/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-pack-err/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-pack-err/src/main.rs')
-rw-r--r--examples/example-pack-err/src/main.rs31
1 files changed, 21 insertions, 10 deletions
diff --git a/examples/example-pack-err/src/main.rs b/examples/example-pack-err/src/main.rs
index 8716333..5bf5066 100644
--- a/examples/example-pack-err/src/main.rs
+++ b/examples/example-pack-err/src/main.rs
@@ -28,6 +28,7 @@
use mingling::prelude::*;
use mingling::setup::StructuralRendererSetup;
+use std::io::Write;
use std::path::PathBuf;
dispatcher!("find", CMDFind => EntryFind);
@@ -100,32 +101,42 @@ fn handle_find_structural(args: EntryFindStructural) -> Next {
/// Renders the successful result with the found directory path.
#[renderer]
-fn render_result_path(path: ResultPath) {
- r_println!("Found directory: {}", path.display());
+fn render_result_path(path: ResultPath) -> RenderResult {
+ let mut render_result = RenderResult::new();
+ writeln!(render_result, "Found directory: {}", path.display()).ok();
+ render_result
}
/// Renders the error when no search path is provided.
#[renderer]
-fn render_error_not_found(_: ErrorNotFound) {
- r_println!("Search path not provided");
+fn render_error_not_found(_: ErrorNotFound) -> RenderResult {
+ let mut render_result = RenderResult::new();
+ writeln!(render_result, "Search path not provided").ok();
+ render_result
}
/// Renders the error when the given path is not a directory.
#[renderer]
-fn render_error_not_dir(err: ErrorNotDir) {
- r_println!("Not a directory: {}", err.info.display());
+fn render_error_not_dir(err: ErrorNotDir) -> RenderResult {
+ let mut render_result = RenderResult::new();
+ writeln!(render_result, "Not a directory: {}", err.info.display()).ok();
+ render_result
}
/// Renders the structural error when no search path is provided.
#[renderer]
-fn render_error_not_found_structural(_: ErrorNotFoundStructural) {
- r_println!("Search path not provided");
+fn render_error_not_found_structural(_: ErrorNotFoundStructural) -> RenderResult {
+ let mut render_result = RenderResult::new();
+ writeln!(render_result, "Search path not provided").ok();
+ render_result
}
/// Renders the structural error when the given path is not a directory.
#[renderer]
-fn render_error_not_dir_structural(err: ErrorNotDirStructural) {
- r_println!("Not a directory: {}", err.info.display());
+fn render_error_not_dir_structural(err: ErrorNotDirStructural) -> RenderResult {
+ let mut render_result = RenderResult::new();
+ writeln!(render_result, "Not a directory: {}", err.info.display()).ok();
+ render_result
}
gen_program!();