Skip to content

Commit 91d5d48

Browse files
committed
update
1 parent d6e561d commit 91d5d48

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ task i18n:fr
4343

4444
```
4545

46+
### docusaurus 配置定制:
47+
48+
- https://docusaurus.io/zh-CN/docs/markdown-features/code-blocks
49+
- 支持 rust 语言高亮
50+
51+
4652
### Reference:
4753

4854
> docs:

docs/01-guide/04-core/02-helloworld.mdx

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,55 @@ sidebar_position: 1
44

55
# Hello World
66

7-
- Rust 最简单的示例:
7+
## Rust 最简单的示例:
88

99

1010

11-
```rust
11+
```rust title="demo/src/main.rs" showLineNumbers
1212

13+
// 函数定义:
14+
fn main() {
15+
// highlight-next-line
16+
println!("Hello, world!"); // println! 是宏, 不是函数
17+
}
1318

19+
```
20+
21+
> 解释:
22+
23+
-`fn` 是定义函数的关键字. 和其他语言类似
24+
-`println!` 是宏(C 宏进阶版, AST树插入+替换), 用于打印输出.
25+
-`;` 语句行结束, 不可省.
26+
- ✅ rust 语句 含有 `;` 和 不含有 `;`, 是有区别的:
27+
- 含有 `;` 时, 是语句
28+
- 不含有 `;`时, 是表达式(自带 return 效果)
29+
30+
31+
## Rust 单元测试:
1432

33+
- 单元测试
1534

35+
```rust title="demo/src/lib.rs" showLineNumbers
36+
37+
#[cfg(test)]
38+
mod tests {
39+
40+
// highlight-next-line
41+
#[test]
42+
fn it_works() {
43+
let result = 2 + 2;
44+
assert_eq!(result, 4); // 断言
45+
}
46+
}
1647

1748
```
1849

50+
> 解释:
51+
52+
-`mod`, 定义`模块` 关键字. rust 通过 mod 组织模块代码, 类似 C++ namespace.
53+
- ✅ std 标准库预定义宏:
54+
-`#[cfg(test)]` = `cfg!`, std 标准库预定义宏, 标注测试模块
55+
-`#[test]` std 标准库预定义宏, 标注单个测试方法
56+
-`assert_eq!` std 标准库预定义宏, 测试断言语句
57+
1958

docusaurus.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ const config = {
198198
prism: {
199199
theme: lightCodeTheme,
200200
darkTheme: darkCodeTheme,
201+
additionalLanguages: ['powershell', 'rust', 'c', 'python'],
201202
},
202203
}),
203204
};

0 commit comments

Comments
 (0)