aboutsummaryrefslogtreecommitdiff
path: root/examples/full-todolist/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/full-todolist/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/full-todolist/src/main.rs')
-rw-r--r--examples/full-todolist/src/main.rs40
1 files changed, 25 insertions, 15 deletions
diff --git a/examples/full-todolist/src/main.rs b/examples/full-todolist/src/main.rs
index e4c5aa6..0748832 100644
--- a/examples/full-todolist/src/main.rs
+++ b/examples/full-todolist/src/main.rs
@@ -7,12 +7,13 @@
//! > This is truly a cliché example, as common as `Hello World`!
use mingling::{
+ LazyInit, LazyRes,
macros::route,
prelude::*,
res::ResExitCode,
- setup::{ExitCodeSetup, StructuralRendererSetup, HelpFlagSetup},
- LazyInit, LazyRes,
+ setup::{ExitCodeSetup, HelpFlagSetup, StructuralRendererSetup},
};
+use std::io::Write;
mod help;
pub use help::*;
@@ -160,38 +161,47 @@ fn handle_clean(
}
}
+/// Renders error when no task description is provided.
#[renderer]
-fn render_error_no_task_description_provided(
+pub fn render_error_no_task_description_provided(
_err: ErrorNoTaskDescriptionProvided,
// ExitCode
ec: &mut ResExitCode,
-) {
- r_println!("No task description provided!");
- r_println!("");
- r_println!("Use `todolist add <desc>` to add a task");
+) -> RenderResult {
+ let mut render_result = RenderResult::new();
+ writeln!(render_result, "No task description provided!").ok();
+ writeln!(render_result).ok();
+ writeln!(render_result, "Use `todolist add <desc>` to add a task").ok();
ec.exit_code = 1;
+ render_result
}
+/// Renders error when no index is provided.
#[renderer]
-fn render_error_no_index_provided(
+pub fn render_error_no_index_provided(
_err: ErrorNoIndexProvided,
// ExitCode
ec: &mut ResExitCode,
-) {
- r_println!("No index provided!");
- r_println!("");
- r_println!("Use `todolist list` to query indexes");
+) -> RenderResult {
+ let mut render_result = RenderResult::new();
+ writeln!(render_result, "No index provided!").ok();
+ writeln!(render_result).ok();
+ writeln!(render_result, "Use `todolist list` to query indexes").ok();
ec.exit_code = 2;
+ render_result
}
+/// Renders error when index is out of bounds.
#[renderer]
-fn render_error_index_out_of_bounds(
+pub fn render_error_index_out_of_bounds(
_err: ErrorIndexOutOfBounds,
// ExitCode
ec: &mut ResExitCode,
-) {
- r_println!("Index out of bounds!");
+) -> RenderResult {
+ let mut render_result = RenderResult::new();
+ writeln!(render_result, "Index out of bounds!").ok();
ec.exit_code = 3;
+ render_result
}
gen_program!();