aboutsummaryrefslogtreecommitdiff
path: root/examples/example-repl-basic/src
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-17 05:49:19 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-17 05:49:19 +0800
commit57c53affe3542cb6bd4e79ee4c18f20a1bd76b2d (patch)
tree1cd4aef44cb7a45a8cd9d520b598f5f181e24c76 /examples/example-repl-basic/src
parentef23cd944402939605c78a4a853ef6e33af02c21 (diff)
refactor!: replace pack! macros with derive-based pipeline types
Remove the `pack!`, `pack_err!`, `pack_structural!`, and `pack_err_structural!` macros, replacing all pipeline type definitions with `#[derive(Grouped)]` and `#[derive(Grouped, Wrap)]` attributes. This changes the generated struct shape from named-field structs with an `inner` field to tuple structs accessed via `.0`, and removes the auto-generated `name` and `info` fields from error types.
Diffstat (limited to 'examples/example-repl-basic/src')
-rw-r--r--examples/example-repl-basic/src/main.rs26
1 files changed, 12 insertions, 14 deletions
diff --git a/examples/example-repl-basic/src/main.rs b/examples/example-repl-basic/src/main.rs
index d0fad6d..9b81ced 100644
--- a/examples/example-repl-basic/src/main.rs
+++ b/examples/example-repl-basic/src/main.rs
@@ -70,7 +70,8 @@ fn main() {
}
// Create error route
-pack!(ErrorDirectoryNotExist = PathBuf);
+#[derive(Grouped, Wrap)]
+pub struct ErrorDirectoryNotExist(PathBuf);
// Create commands: cd ls exit
dispatcher!("cd", EntryCd);
@@ -79,16 +80,18 @@ dispatcher!("exit", EntryExit);
dispatcher!("clear", EntryClear);
// Define data needed for the cd command's execution phase
-pack!(StateChangeDirectory = String);
+#[derive(Grouped, Wrap)]
+pub struct StateChangeDirectory(String);
// Define data needed for the ls command's rendering phase
-pack!(ResultList = Vec<String>);
+#[derive(Grouped, Wrap)]
+pub struct ResultList(Vec<String>);
// Parse cd command arguments
#[chain]
fn parse_cd_args(prev: EntryCd) -> Next {
let join = prev.pick_or_default(&arg![String]).unwrap();
- StateChangeDirectory::new(join).into()
+ StateChangeDirectory(join).into()
}
// Execute directory change
@@ -96,12 +99,12 @@ fn parse_cd_args(prev: EntryCd) -> Next {
fn handle_cd(prev: StateChangeDirectory, current_dir: &mut ResCurrentDir) -> Next {
use just_fmt::fmt_path::fmt_path;
- let join = prev.inner;
+ let join = prev.0;
let new_dir = fmt_path(current_dir.dir.join(join)).unwrap_or_default();
// If the path is not found, route to error handling
if !new_dir.exists() {
- return ErrorDirectoryNotExist::new(new_dir).to_render();
+ return ErrorDirectoryNotExist(new_dir).to_render();
}
current_dir.dir = new_dir;
@@ -126,14 +129,14 @@ fn handle_ls(_prev: EntryLs, current_dir: &ResCurrentDir) -> Next {
.collect();
// Render ResultList
- ResultList::new(entries).to_render()
+ ResultList(entries).to_render()
}
/// Render ResultList data
#[renderer]
fn render_list(list: ResultList) -> RenderResult {
let mut render_result = RenderResult::new();
- for item in list.inner {
+ for item in list.0 {
writeln!(render_result, "{}", item).ok();
}
render_result
@@ -160,12 +163,7 @@ fn handle_clear(_prev: EntryClear) {
#[renderer]
fn render_error_directory_not_exist(err: ErrorDirectoryNotExist) -> RenderResult {
let mut render_result = RenderResult::new();
- writeln!(
- render_result,
- "Directory not found: {}",
- err.inner.display()
- )
- .ok();
+ writeln!(render_result, "Directory not found: {}", err.0.display()).ok();
render_result
}