Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c9edda6

Browse files
committed
update
1 parent 9d8074a commit c9edda6

File tree

5 files changed

+136
-7
lines changed

5 files changed

+136
-7
lines changed

‎docs/01-guide/00-roadmap.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ sidebar_position: 0
44

55
# 🦀 Rust 学习路线图
66

7-
## 阅读顺序:
7+
## 阅读顺序: {#way}
88

99
-[Rust 快速开始](intro/)
1010
-[Rust 基础语法](core/intro): 先掌握语法

‎docs/01-guide/02-tips/00-rule.mdx‎ renamed to ‎docs/01-guide/02-tips/00-intro/01-rule.mdx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
sidebar_position: 1
33
---
44

5-
# ❗️ 隐式约定
5+
# 隐式约定
66

77

88
:::caution
9-
- Rust 是`强规范`语言, 有些规范是`隐式`的, 有些规范是`显式`的.
10-
- 很多语言都存在`隐式`约定, 拿 python 举例:
9+
- Rust 是`强规范`语言, 有些规范是`隐式`的, 有些规范是`显式`的.
10+
- 很多语言都存在`隐式`约定, 拿 python 举例:
1111
- python 的`缩进`(4个空格)
1212
- `__init__` 方法: 类初始化
1313
- `__init__.py` 文件: 常模块批量导出, 用于区分一个普通目录 vs python module, 且必须存在
1414
- `self` 参数: 类方法的第一个参数
15-
- Rust 中, 有`大量隐式`约定, 从编译工具链, cargo 工具, 语言语法设计, 都有大量隐式约定.
15+
- Rust 中, 有`大量隐式`约定, 从编译工具链, cargo 工具, 语言语法设计, 都有大量隐式约定.
1616
- `src/`: 项目源码目录
1717
- `src/main.rs`: 用于存放主程序
1818
- `src/lib.rs`: 用于存放库文件
1919
- `src/bin/`: 用于存放多个主程序(非常隐式, 虽然是官方规范, 但个人不建议使用, 更建议采用 substrate 的做法)
2020
- `cargo.toml`: 项目配置文件, 包含非常灵活+强大+复杂的配置规则(吊打其他语言)
2121
- `mod.rs`: 用于存放模块文件, 常用于批量导出 rust modules
2222
- `build.rs`: 用于存放构建脚本
23-
- 这些`隐式`约定, 会给`初学者`带来大量困扰.
23+
- ❗️️ 这些`隐式`约定, 会给`初学者`带来大量困扰.
2424
- 经常因为不了解隐含规则, 导致无法理解+编译 rust 项目.
2525
- 虽然`官方文档`都会提及, 但`过于分散`(初学者要花很久才触碰到, 但其实入门就应该知道).
2626
- 此处, 会将所有隐式约定, 一一列举+说明, 以便初学者快速知晓, 不至于被这些绊倒.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# 对比其他语言
6+
7+
:::caution
8+
9+
- Rust 兼顾 OOP(面向对象) 和 FP(函数式) 编程范式.
10+
- 语法上, 大量借鉴其他语言优秀特性.
11+
- 选取主流具有`代表性`的通用语言做对比:
12+
- go
13+
- python(代表 ruby/js 等同一类语言)
14+
- c++
15+
16+
:::
17+
18+
> rust OOP(面向对象编程) 特性:
19+
20+
- `对象、封装、继承和多态`, 对应 Rust 的一些特性: `struct, impl, pub, trait`
21+
22+
> rust FP(functional programming)函数式语言特性:
23+
24+
- `闭包(Closures)`, 一个可以储存在变量里的类似函数的结构
25+
- `迭代器(Iterators)`, 一种处理元素序列的方式
26+
- `链式操作`
27+
28+
## 与 OCaml 关系
29+
30+
:::tip
31+
32+
- Rust 首个编译器, 是使用 [OCaml](https://ocaml.org/) 实现.
33+
34+
:::
35+
36+
-[OCaml](https://ocaml.org/) 语言, 是函数式语言.
37+
- ✅ Rust 语言, 包含大量函数式特性.
38+
-[OCaml在写编译器上比Haskell好在哪?为何Rust第一个版本采用了OCaml?](https://www.zhihu.com/question/62971835)
39+
40+
## 与 C/C++/Zig 关系
41+
42+
:::tip
43+
44+
- `Zig/Rust`, 是 `C/C++` 的替代品.
45+
- Rust: a better C++. 和 C++ 语法同样复杂
46+
- Zig: a better C. 语法简单 + 功能强大.
47+
48+
:::
49+
50+
> 与 C/C++ 关系:
51+
52+
- ✅ Rust 正在大量重写 C/C++ 生态.
53+
54+
> 与 Zig 关系:
55+
56+
- ✅ Zig 目前比较小众, 不单独讨论. 有兴趣的可以自行搜索.
57+
-[Zig vs Rust](https://www.ziglang.org/#Zig-vs-Rust)
58+
- ✅ 长期看, Zig 与 Rust 会有竞争关系, 也有互补关系. 总体是 互补 > 竞争.
59+
- ✅ 协同效应: ⭐️⭐️⭐️.
60+
61+
## 与 Go 关系
62+
63+
:::tip
64+
65+
- Rust 对 Go 是全方位的`替代`关系.
66+
- Go 和 Rust 相比, 除了语法简单, 几乎没有优势.
67+
- 协同效应: ⭐️️
68+
- ❌ 非常不推荐 `Rust + Go` 协作开发.
69+
-`Rust + Go` 协同收益 < `Rust + Python/Ruby/Nodejs/PHP`.
70+
71+
:::
72+
73+
74+
75+
> 相似点:
76+
77+
- rust 的 `struct` 类似 go 的 `struct`.
78+
- 基础使用相近.
79+
- rust 的 `trait` 类似 go 的 `interface`.
80+
- 二者使用上, 优雅程度不相上下.
81+
- rust 更灵活.
82+
- `rust workspace` 类似 `go.work`.
83+
- 二者都是为了解决 `多项目` 开发的问题.
84+
- `rust cargo.toml` 类似 `go.mod`.
85+
- 二者都是为了解决 `依赖管理` 的问题.
86+
- `rust cargo 指令` 类似 `go mod 指令`.
87+
- 都是包管理工具.
88+
- cargo 更加强大
89+
90+
> 不同点:
91+
92+
- rust `No GC` vs go `GC`.
93+
- 语法上的差异, 无需过多讨论.
94+
95+
## 与 Python 关系
96+
97+
:::tip
98+
99+
- 可以基于 `FFI` 使用 rust, 为 Python 编写底层库.
100+
- 协同效应: ⭐️⭐️⭐️⭐️⭐️.
101+
- 兼顾开发效率和性能.
102+
- 前期开发, 用 Python, 后期性能瓶颈, 用 Rust 重构/重写.
103+
104+
:::
105+
106+
107+
108+
109+
> 相似点:
110+
111+
- rust `impl` + `struct` 类似 python `class`.
112+
- rust `self` 参数 类似 python 类 `self` 参数 .
113+
- rust `mod.rs` 类似 python `__init__.py`.
114+
- 功能和作用基本一致.
115+
- rust `函数式`相关特性, 基本和 python 相关特性类似.
116+
117+
> 不同点:
118+
119+
- rust `No GC` vs python `GC`.
120+
- 语法上的差异, 无需过多讨论.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"label": "❗️扫盲",
3+
"position": 0,
4+
"collapsed": true,
5+
"link": {
6+
"type": "generated-index",
7+
"description": "Rust 轻松时刻."
8+
}
9+
}

‎docs/01-guide/02-tips/03-code-snippet/01-intro.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
sidebar_position: 1
33
---
44

5-
# Code Snippet
5+
# 基础操作
66

77
- 常用代码片段
88
- 多语言使用者, 频繁切换语言, 会导致一些基础用法混淆.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /