diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/_zh_CN/index.html | 10 | ||||
| -rw-r--r-- | docs/_zh_CN/pages/other/naming_rule.md | 33 | ||||
| -rw-r--r-- | docs/doc.html | 10 | ||||
| -rw-r--r-- | docs/pages/other/naming_rule.md | 34 |
4 files changed, 63 insertions, 24 deletions
diff --git a/docs/_zh_CN/index.html b/docs/_zh_CN/index.html index 12cde6c..7adaa98 100644 --- a/docs/_zh_CN/index.html +++ b/docs/_zh_CN/index.html @@ -63,6 +63,16 @@ depth: 2, }, plugins: [ + function (hook) { + hook.beforeEach(function (content) { + return content + .split("\n") + .filter(function (line) { + return !line.startsWith("@@@"); + }) + .join("\n"); + }); + }, [ "flexible-alerts", { diff --git a/docs/_zh_CN/pages/other/naming_rule.md b/docs/_zh_CN/pages/other/naming_rule.md index 264cffd..1f1ff84 100644 --- a/docs/_zh_CN/pages/other/naming_rule.md +++ b/docs/_zh_CN/pages/other/naming_rule.md @@ -33,9 +33,9 @@ Res + 名称 名称 + Setup ``` -| 示例 | 说明 | -| ---------------------- | ---------------------------------------------- | -| `BasicSetup` | 基础初始化(`--quiet`、`--help`、`--confirm`) | +| 示例 | 说明 | +| ------------------------- | ---------------------------------------------- | +| `BasicSetup` | 基础初始化(`--quiet`、`--help`、`--confirm`) | | `StructuralRendererSetup` | 通用渲染器初始化(`--json`、`--yaml` 等) | ### 分发器 @@ -148,9 +148,13 @@ Error + 描述 | 资源(可变) | `counter`、`cache`、`session` 等 | ```rust -// NOT VERIFIED +@@@ pack!(EntryRemoteAdd = Vec<String>); +@@@ #[derive(Default, Clone)] +@@@ struct ResDatabase { } +@@@ #[derive(Default, Clone)] +@@@ struct ResCurrentDir { } #[chain] -fn handle_remote_add(args: EntryRemoteAdd, cwd: &ResCurrentDir, db: &mut ResDatabase) -> Next { +fn handle_remote_add(args: EntryRemoteAdd, cwd: &ResCurrentDir, db: &mut ResDatabase) { // args: 入口数据 // cwd: 注入的不可变资源 // db: 注入的可变资源 @@ -162,36 +166,41 @@ fn handle_remote_add(args: EntryRemoteAdd, cwd: &ResCurrentDir, db: &mut ResData ## 完整示例 ```rust -// NOT VERIFIED +@@@ #[derive(Default, Clone)] +@@@ struct ResDatabase { } +@@@ impl ResDatabase { fn has_remote(&self, remote: &String) -> bool { true } } +@@@ pack!(StateOperationRemotes = String); +@@@ pack!(ResultRemoteAdded = String); +@@@ pack!(ErrorRepositoryNotFound = String); // 分发器 dispatcher!("remote.add", CMDRemoteAdd => EntryRemoteAdd); // 入口 → 状态 #[chain] fn handle_remote_add(args: EntryRemoteAdd) -> Next { - StateOperationRemotes::new(...).to_chain() + StateOperationRemotes::default().to_chain() } // 状态 → 错误或结果 #[chain] fn handle_state_operation_remotes(state: StateOperationRemotes, db: &ResDatabase) -> Next { - if db.has_remote(&state.name) { - ErrorRepositoryNotFound::new(...).to_render() + if db.has_remote(&state.inner) { + ErrorRepositoryNotFound::new(state.inner).to_render() } else { - ResultRemoteAdded::new(...).to_render() + ResultRemoteAdded::new(state.inner).to_render() } } // 结果渲染 #[renderer] fn render_remote_added(result: ResultRemoteAdded) { - r_println!("Remote added: {}", result.name); + r_println!("Remote added: {}", result.inner); } // 错误渲染 #[renderer] fn render_error_repository_not_found(err: ErrorRepositoryNotFound) { - r_println!("Error: remote '{}' not found", err.name); + r_println!("Error: remote '{}' not found", err.inner); } ``` diff --git a/docs/doc.html b/docs/doc.html index 8640565..783ccb4 100644 --- a/docs/doc.html +++ b/docs/doc.html @@ -58,6 +58,16 @@ depth: 2, }, plugins: [ + function (hook) { + hook.beforeEach(function (content) { + return content + .split("\n") + .filter(function (line) { + return !line.startsWith("@@@"); + }) + .join("\n"); + }); + }, [ "flexible-alerts", { diff --git a/docs/pages/other/naming_rule.md b/docs/pages/other/naming_rule.md index 4f4efe8..21d7947 100644 --- a/docs/pages/other/naming_rule.md +++ b/docs/pages/other/naming_rule.md @@ -33,9 +33,9 @@ Setups are initialization steps executed at program startup, registered via `wit Name + Setup ``` -| Example | Description | -| ---------------------- | ---------------------------------------------------------- | -| `BasicSetup` | Basic initialization (`--quiet`, `--help`, `--confirm`) | +| Example | Description | +| ------------------------- | ------------------------------------------------------------- | +| `BasicSetup` | Basic initialization (`--quiet`, `--help`, `--confirm`) | | `StructuralRendererSetup` | structural renderer initialization (`--json`, `--yaml`, etc.) | ### Dispatcher @@ -148,9 +148,13 @@ Error + Description | Resource (mutable) | `counter`, `cache`, `session`, etc. | ```rust -// NOT VERIFIED +@@@ pack!(EntryRemoteAdd = Vec<String>); +@@@ #[derive(Default, Clone)] +@@@ struct ResDatabase { } +@@@ #[derive(Default, Clone)] +@@@ struct ResCurrentDir { } #[chain] -fn handle_remote_add(args: EntryRemoteAdd, cwd: &ResCurrentDir, db: &mut ResDatabase) -> Next { +fn handle_remote_add(args: EntryRemoteAdd, cwd: &ResCurrentDir, db: &mut ResDatabase) { // args: entry data // cwd: injected immutable resource // db: injected mutable resource @@ -162,37 +166,43 @@ fn handle_remote_add(args: EntryRemoteAdd, cwd: &ResCurrentDir, db: &mut ResData ## Complete Example ```rust -// NOT VERIFIED +@@@ #[derive(Default, Clone)] +@@@ struct ResDatabase { } +@@@ impl ResDatabase { fn has_remote(&self, remote: &String) -> bool { true } } +@@@ pack!(StateOperationRemotes = String); +@@@ pack!(ResultRemoteAdded = String); +@@@ pack!(ErrorRepositoryNotFound = String); // Dispatcher dispatcher!("remote.add", CMDRemoteAdd => EntryRemoteAdd); // Entry → State #[chain] fn handle_remote_add(args: EntryRemoteAdd) -> Next { - StateOperationRemotes::new(...).to_chain() + StateOperationRemotes::default().to_chain() } // State → Error or Result #[chain] fn handle_state_operation_remotes(state: StateOperationRemotes, db: &ResDatabase) -> Next { - if db.has_remote(&state.name) { - ErrorRepositoryNotFound::new(...).to_render() + if db.has_remote(&state.inner) { + ErrorRepositoryNotFound::new(state.inner).to_render() } else { - ResultRemoteAdded::new(...).to_render() + ResultRemoteAdded::new(state.inner).to_render() } } // Result rendering #[renderer] fn render_remote_added(result: ResultRemoteAdded) { - r_println!("Remote added: {}", result.name); + r_println!("Remote added: {}", result.inner); } // Error rendering #[renderer] fn render_error_repository_not_found(err: ErrorRepositoryNotFound) { - r_println!("Error: remote '{}' not found", err.name); + r_println!("Error: remote '{}' not found", err.inner); } + ``` <p align="center" style="font-size: 0.85em; color: gray;"> |
