aboutsummaryrefslogtreecommitdiff
path: root/docs/pages
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-06-30 07:06:07 +0800
committer魏曹先生 <1992414357@qq.com>2026-06-30 07:06:07 +0800
commit793e6b538c95c54c647f7127d634818547028999 (patch)
tree6e7b0e0b85a208751116015b0c3e531ec928321d /docs/pages
parent2aa0de3852611aed2823fd40a3f6f47b8f50f0cd (diff)
feat(docs): add @@@ hidden code block support for compile-tested
examples
Diffstat (limited to 'docs/pages')
-rw-r--r--docs/pages/other/naming_rule.md34
1 files changed, 22 insertions, 12 deletions
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;">