aboutsummaryrefslogtreecommitdiff
path: root/docs/_zh_CN/pages/other/features.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/_zh_CN/pages/other/features.md')
-rw-r--r--docs/_zh_CN/pages/other/features.md50
1 files changed, 25 insertions, 25 deletions
diff --git a/docs/_zh_CN/pages/other/features.md b/docs/_zh_CN/pages/other/features.md
index 04aa0ab..8b19b31 100644
--- a/docs/_zh_CN/pages/other/features.md
+++ b/docs/_zh_CN/pages/other/features.md
@@ -19,15 +19,15 @@
```rust
// Features: ["async"]
-
+
pack!(StateFoo = ());
-
+
#[chain]
async fn handle_state_foo(foo: StateFoo) -> Next {
StateFoo::new(())
}
```
-
+
详见 [示例](https://mingling-rs.github.io/mingling/docs/example-viewer.html?name=example-async-support)
## 特性 `builds`
@@ -41,13 +41,13 @@ async fn handle_state_foo(foo: StateFoo) -> Next {
```rust
// Features: ["builds", "comp"]
use mingling::build::build_comp_scripts;
-
+
fn main() {
// 为 `myprogram` 生成补全脚本
build_comp_scripts("myprogram").unwrap();
}
```
-
+
## 特性 `clap`
**介绍:**
@@ -108,17 +108,17 @@ fn main() {
```rust
// Features: ["extra_macros"]
-
+
pack!(StatePrev1 = ());
pack!(StatePrev2 = ());
-
+
pack!(StateNext = ());
-
+
#[chain]
fn handle_state_prev2(_p: StatePrev2) {
// 无 Next 的 #[chain] 可以直接不返回值
}
-
+
#[chain]
fn handle_state_prev1(_p: StatePrev1) -> Next {
let foo = 1;
@@ -131,19 +131,19 @@ fn handle_state_prev1(_p: StatePrev1) -> Next {
}
}
```
-
+
### `#[program_setup]`
```rust
// Features: ["extra_macros"]
use mingling::{macros::program_setup, Program};
-
+
fn main() {
let mut program = ThisProgram::new();
program.with_setup(NoErrorSetup);
program.exec_and_exit();
}
-
+
#[program_setup]
fn no_error_setup(program: &mut Program<ThisProgram>) {
program.global_flag(["--no-error"], |program| {
@@ -151,24 +151,24 @@ fn no_error_setup(program: &mut Program<ThisProgram>) {
});
}
```
-
+
### `entry!`
```rust
// Features: ["extra_macros"]
use mingling::macros::entry;
-
+
pack!(EntryHello = Vec<String>);
-
+
fn main() {
let result = handle_hello(entry!("--name", "Bob")).into();
// ... 此处为断言逻辑
}
-
+
#[chain]
fn handle_hello(args: EntryHello) {}
```
-
+
### `group!`
将外部类型注册为程序组成员,无需修改原始类型的定义。
@@ -178,12 +178,12 @@ fn handle_hello(args: EntryHello) {}
// Features: ["extra_macros"]
use mingling::macros::group;
use std::num::ParseIntError;
-
+
// 将 std::num::ParseIntError 注册为组成员。
// 注册后,ParseIntError 可用于 #[chain] 和 #[renderer] 函数中。
group!(std::num::ParseIntError);
```
-
+
### `pack_err!`
创建带自动 `name: String` 字段的错误结构体,字段值自动设为结构体名的蛇形命名。
@@ -192,20 +192,20 @@ group!(std::num::ParseIntError);
```rust
// Features: ["extra_macros"]
use std::path::PathBuf;
-
+
// 简单形式——仅包含 name 字段:
pack_err!(ErrorNotFound);
// 生成:
// struct ErrorNotFound { pub name: String }
// impl Default for ErrorNotFound { ... }
-
+
// 带类型的形式——包含额外的 info 字段:
pack_err!(ErrorNotDir = PathBuf);
// 生成:
// struct ErrorNotDir { pub name: String, pub info: PathBuf }
// impl ErrorNotDir { pub fn new(info: PathBuf) -> Self { ... } }
```
-
+
</details>
## 特性 `structural_renderer`
@@ -258,17 +258,17 @@ pack_err!(ErrorNotDir = PathBuf);
# Cargo.toml
[dependencies.mingling]
features = ["pathf"]
-
+
[build-dependencies.mingling]
features = ["builds", "pathf"]
```
-
+
```rust
// BUILD TIME
// Features: ["pathf"]
analyze_and_build_type_mapping().unwrap();
```
-
+
详见 [示例](https://mingling-rs.github.io/mingling/docs/example-viewer.html?name=example-pathfinder)
## 特性 `parser`