Skip to content

Commit 4f78854

Browse files
committed
上线极客学院wiki
添加 toc、config、cover文件与校对格式
1 parent 3d4426a commit 4f78854

File tree

115 files changed

+620
-70
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+620
-70
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
[build-url]: https://travis-ci.org/rustcc/RustPrimer
77

88
The Rust primer for beginners.
9+
910
给初学者的Rust中文教程。
1011

1112
## 在线阅读地址

TOC.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
- [初识Rust](1st-glance/README.md)
2+
- [安装Rust](install/preface.md)
3+
- [Linux](install/install_rust_on_linux.md)
4+
- [Mac](install/install_rust_on_mac_os.md)
5+
- [Windows](install/install_rust_on_windows.md)
6+
- [版本管理工具: rustup](install/rustup.md)
7+
- [编辑器](editors/preface.md)
8+
- [前期准备](editors/before.md)
9+
- [vim](editors/vim.md)
10+
- [emacs](editors/emacs.md)
11+
- [vscode](editors/vscode.md)
12+
- [atom](editors/atom.md)
13+
- [sublime](editors/sublime.md)
14+
- [visual studio](editors/visualstudio.md)
15+
- [spacemacs](editors/spacemacs.md)
16+
- [Rust快速入门](quickstart/quickstart.md)
17+
- [Rust旅程](quickstart/rust-travel.md)
18+
- [变量绑定与原生类型](quickstart/primitive-type.md)
19+
- [数组、动态数组和字符串](quickstart/vector-string.md)
20+
- [结构体与枚举](quickstart/struct-enum.md)
21+
- [控制流](quickstart/control-flow.md)
22+
- [函数与方法](quickstart/function-method.md)
23+
- [特性](quickstart/trait.md)
24+
- [注释与文档](quickstart/comments-document.md)
25+
- [输入输出流](quickstart/io-stream.md)
26+
- [Cargo项目管理器](cargo-projects-manager/cargo-projects-manager.md)
27+
- [基本程序结构](flow/preface.md)
28+
- [注释](flow/comment.md)
29+
- [条件](flow/condition.md)
30+
- [循环](flow/repetition.md)
31+
- [类型、运算符和字符串](type/preface.md)
32+
- [基础类型](type/types.md)
33+
- [复合类型](type/compound-types.md)
34+
- [字符串类](type/string.md)
35+
- [基础运算符和字符串格式化](type/operator-and-formatting.md)
36+
- [函数](function/overview.md)
37+
- [函数参数](function/arguement.md)
38+
- [函数返回值](function/return_value.md)
39+
- [语句和表达式](function/statement_expression.md)
40+
- [高阶函数](function/higher_order_function.md)
41+
- [模式匹配](match/overview.md)
42+
- [match关键字](match/match.md)
43+
- [模式 pattern](match/pattern.md)
44+
- [特征 Trait](trait/overview.md)
45+
- [trait关键字](trait/trait.md)
46+
- [trait对象](trait/trait-object.md)
47+
- [泛型](generic/generic.md)
48+
- [可变性、所有权、租借和生命期](ownership-system/ownership_system.md)
49+
- [所有权](ownership-system/ownership.md)
50+
- [引用和借用](ownership-system/borrowing_reference.md)
51+
- [生命周期](ownership-system/lifetime.md)
52+
- [闭包](closure/overview.md)
53+
- [闭包的语法](closure/syntax.md)
54+
- [闭包的实现](closure/implementation.md)
55+
- [闭包作为参数和返回值](closure/as_argument_return_value.md)
56+
- [集合类型 Collections](collections/overview.md)
57+
- [动态数组 Vec](collections/vec.md)
58+
- [哈希表 HashMap](collections/hashmap.md)
59+
- [迭代器](iterator/overview.md)
60+
- [迭代器、适配器、消费者](iterator/iterator.md)
61+
- [模块和包系统、Prelude](module/preface.md)
62+
- [模块 module 和包 crate](module/module.md)
63+
- [Prelude](module/prelude.md)
64+
- [Option、Result与错误处理](error-handling/option-result.md)
65+
- [输入与输出](io/io.md)
66+
- [宏系统](macro/macro.md)
67+
- [堆、栈与Box](heap-stack/heap-stack.md)
68+
- [几种智能指针](rcarc/preface.md)
69+
- [Rc, Arc](rcarc/rcarc.md)
70+
- [Mutex, RwLock](rcarc/mutex.md)
71+
- [Cell, RefCell](rcarc/cell.md)
72+
- [类型系统中的几个常见 Trait](intoborrow/preface.md)
73+
- [Into/From 及其在 String 和 &str 互转上的应用](intoborrow/into.md)
74+
- [AsRef, AsMut](intoborrow/asref.md)
75+
- [Borrow, BorrowMut, ToOwned](intoborrow/borrow.md)
76+
- [Deref 与 Deref coercions](intoborrow/deref.md)
77+
- [Cow 及其在 String 和 &str 上的应用](intoborrow/cow.md)
78+
- [Send 和 Sync](marker/sendsync.md)
79+
- [并发,并行,多线程编程](concurrency-parallel-thread/preface.md)
80+
- [线程](concurrency-parallel-thread/thread.md)
81+
- [消息传递](concurrency-parallel-thread/message-passing.md)
82+
- [共享内存](concurrency-parallel-thread/share-memory.md)
83+
- [同步](concurrency-parallel-thread/synchronize.md)
84+
- [并行](concurrency-parallel-thread/parallel.md)
85+
- [Unsafe、原始指针](unsafe-rawpointer/preface.md)
86+
- [Unsafe](unsafe-rawpointer/unsafe.md)
87+
- [原始指针](unsafe-rawpointer/raw-pointer.md)
88+
- [FFI](ffi/preface.md)
89+
- [rust调用ffi函数](ffi/calling-ffi-function.md)
90+
- [将rust编译成库](ffi/compiling-rust-to-lib.md)
91+
- [运算符重载](operator-overloading/operator.md)
92+
- [属性和编译器参数](attr-and-compiler-arg/preface.md)
93+
- [属性](attr-and-compiler-arg/attribute.md)
94+
- [编译器参数](attr-and-compiler-arg/rustc-option.md)
95+
- [Cargo参数配置](cargo-detailed-cfg/cargo-detailed-cfg.md)
96+
- [测试与评测](testing/preface.md)
97+
- [测试 (testing)](testing/threearchtest.md)
98+
- [评测 (benchmark)](testing/bench.md)
99+
- [代码风格](coding-style/style.md)
100+
- [Any与反射](any/any.md)
101+
- [安全(safe)](safe/safety.md)
102+
- [常用数据结构实现](data-structure/preface.md)
103+
- [栈结构](data-structure/stack.md)
104+
- [队列](data-structure/queue.md)
105+
- [二叉树](data-structure/binary_tree.md)
106+
- [优先队列](data-structure/priority_queue.md)
107+
- [链表](data-structure/linked_list.md)
108+
- [图结构](data-structure/graph.md)
109+
- [标准库介绍](std/overview.md)
110+
- [系统命令:调用grep](std/process.md)
111+
- [目录操作:简单grep](std/fs-and-path.md)
112+
- [网络模块:W回音](std/net.md)
113+
- [实战篇](action/preface.md)
114+
- [实战:Json处理](action/json_data/readme.md)
115+
- [实战:Web 应用开发入门](action/mysite/readme.md)
116+
- [实战:使用Postgresql数据库](action/db/readme.md)
117+
- [附录-术语表](appendix/glossary.md)

action/db/readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ pub fn query_all(conn: &Connection,query: &str){
142142
}
143143

144144
```
145+
145146
然后在main.rs 中调用相应的函数代码如下
146147
1. extern db ,引入db,也就是将项目本身引入
147148
2. use db 使用db,中的可以被引入的函数
@@ -182,6 +183,7 @@ fn main() {
182183
```
183184

184185
自己遇到的坑
186+
185187
- 创建连接函数时,连接必须有一个返回值,所以必须指定返回值的类型,
186188
对于一个写python的人而言,我觉得是痛苦的,我想按照官方的写法match
187189
一下,发现可能产生多个返回值。在编译时直接无法通过编译,所以最终
@@ -202,7 +204,9 @@ pub fn query_all(conn: &Connection,query: &str){
202204
}
203205

204206
```
207+
205208
报错如下:
209+
206210
``` rust
207211
vagrant@ubuntu-14:~/tmp/test/rustprimer/db$ cargo run
208212
Compiling db v0.1.0 (file:///home/vagrant/tmp/test/rustprimer/db)
@@ -217,6 +221,7 @@ error: aborting due to previous error
217221
Could not compile `db`.
218222

219223
```
224+
220225
然后去查看了关于postgres模块的所有函数,尝试了无数种办法,依旧没有解决。
221226

222227
可能自己眼高手低,如果从头再把rust的相关教程看一下,可能很早就发现这个问题,

action/json_data/readme.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ json是一种比较重要的格式,尤其是现在的web开发领域,json相
55
rust中的json处理依赖 cargo 中的rustc-serialize模块
66

77
###先简单的创建一个rust项目工程
8+
89
``` rust
910
$ cargo new json_data --bin
1011
```
12+
1113
生成文件树:
14+
1215
```shell
1316
vagrant@ubuntu-14:~/tmp/test/rustprimer$ tree
1417
.
@@ -19,6 +22,7 @@ vagrant@ubuntu-14:~/tmp/test/rustprimer$ tree
1922
2023
2124
```
25+
2226
生成项目`json_data`,项目下文件介绍:
2327

2428
- Caogo.toml ,文件中填写一些项目的相关信息,比如版本号,联系人,项目名,文件的内容如下:
@@ -39,6 +43,7 @@ authors = ["wangxxx <[email protected]>"]
3943

4044
rustc-serialize 这个是第三方的模块,需要从[cargo](https://crates.io/crates/rustc-serialize)下载。
4145
下载很简单,只需修改一下cargo.toml文件就行了.
46+
4247
```toml
4348
[package]
4449
name = "json_data"
@@ -49,12 +54,16 @@ authors = ["wangxxx <[email protected]>"]
4954
rustc-serialize = "0.3.18"
5055
5156
```
57+
5258
然后执行在当前目录执行:
59+
5360
```
5461
$ cargo build
5562
```
63+
5664
*注意一个问题由于国内网络访问github不稳定,这些第三方库很多托管在github上,所以可能需要修改你的
5765
网络访问*
66+
5867
1. 在安装rust之后,会在你的用户目录之下生成一个`.cargo`文件夹,进入这个文件夹
5968
2. 在`.cargo`文件夹下,创建一个`config`文件,在文件中填写中科大软件源,可能以后会出现其他的源,先用这个
6069
3. `config`文件内容如下
@@ -64,6 +73,7 @@ $ cargo build
6473
index = "git://crates.mirrors.ustc.edu.cn/index"
6574
6675
```
76+
6777
cargo build 执行之后的提示信息
6878

6979
```
@@ -72,6 +82,7 @@ cargo build 执行之后的提示信息
7282
Compiling rustc-serialize v0.3.18 (registry git://crates.mirrors.ustc.edu.cn/index)
7383
Compiling json_data v0.1.0 (file:///home/vagrant/tmp/test/rustprimer/json_data)
7484
```
85+
7586
再次执行tree命令:
7687

7788
```
@@ -90,6 +101,7 @@ cargo build 执行之后的提示信息
90101
`-- native
91102
92103
```
104+
93105
可以看到多了很多文件,重点关注`cargo.lock`,开打文件:
94106

95107
```toml
@@ -106,9 +118,11 @@ version = "0.3.18"
106118
source = "registry+git://crates.mirrors.ustc.edu.cn/index"
107119

108120
```
121+
109122
是关于项目编译的一些依赖信息
110123

111124
还有生成了target文件夹,生成了可执行文件json_data,因为main.rs中的执行结果就是打印`hello world`
125+
112126
```
113127
$ cargo run
114128
@@ -152,4 +166,5 @@ fn main() {
152166
}
153167

154168
```
169+
155170
当然我们也可以在文本中作为api的返回结果使用,下来的章节中,我们将讨论这个问题

action/mysite/readme.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ rust目前比较有名的框架是iron和nickel,我们两个都写一下简单
1010
接上一篇,使用cargo获取第三方库。`cargo new mysite --bin`
1111

1212
在cargo.toml中添加iron的依赖,
13+
1314
```toml
1415
[dependencies]
1516
iron = "*"
1617
```
18+
1719
然后build将依赖下载到本地 `cargo build`
1820

1921
如果报ssl错误,那可能你需要安装linux的ssl开发库。
@@ -32,6 +34,7 @@ fn main() {
3234
}).http("localhost:3000").unwrap();
3335
}
3436
```
37+
3538
然后运行
3639

3740
`cargo run`
@@ -53,6 +56,7 @@ let plus_one = |x: i32| x + 1;
5356

5457
assert_eq!(2, plus_one(1));
5558
```
59+
5660
具体的怎么使用 ,可以暂时不用理会,因为你只要知道如何完成web,因为我也不会。。
5761
结合之前一章节的json处理,我们来看看web接口怎么返回json,当然也要 rustc_serialize 放到 cargo.toml 中
5862

@@ -82,12 +86,14 @@ fn main() {
8286
println!("On 3000");
8387
}
8488
```
89+
8590
执行 cargo run 使用 curl 测试结果:
8691

8792
```
8893
curl localhost:3000
8994
{"msg":"Hello, World"}
9095
```
96+
9197
当然可以可以实现更多的业务需求,通过控制自己的json。
9298

9399
既然有了json了,如果要多个路由什么的,岂不是完蛋了,所以不可能这样的,我们需要考虑一下怎么实现路由的定制
@@ -133,8 +139,10 @@ fn main() {
133139
Iron::new(router).http("localhost:3000").unwrap();
134140
}
135141
```
142+
136143
这次添加了路由的实现和获取客户端发送过来的数据,有了get,post,所以现在一个基本的api网站已经完成了。不过
137144
并不是所有的网站都是api来访问,同样需要html模版引擎和直接返回静态页面。等等
145+
138146
```
139147
vagrant@ubuntu-14:~/tmp/test/rustprimer/mysite$ cargo build
140148
Compiling mysite v0.1.0 (file:///home/vagrant/tmp/test/rustprimer/mysite)
@@ -146,6 +154,7 @@ src/main.rs:29:36: 29:52 help: candidate #1: use `std::io::Read`
146154
error: aborting due to previous error
147155
Could not compile `mysite`.
148156
```
157+
149158
编译出错了,太糟糕了,提示说没有read_to_string这个方法,然后我去文档查了一下,发现有[read_to_string方法](http://ironframework.io/doc/iron/request/struct.Body.html)
150159
再看提示信息
151160

@@ -201,6 +210,7 @@ let mut buffer = String::new();
201210
try!(f.read_to_string(&mut buffer));
202211

203212
```
213+
204214
用法比较简单,我们修改一下刚刚的函数:
205215

206216
```
@@ -213,12 +223,14 @@ fn set_greeting(request: &mut Request) -> IronResult<Response> {
213223
Ok(Response::with((status::Ok, payload)))
214224
}
215225
```
226+
216227
从request中读取字符串,读取的结果存放到payload中,然后就可以进行操作了,编译之后运行,使用curl提交一个post数据
217228

218229
```
219230
$curl -X POST -d '{"msg":"Just trust the Rust"}' http://localhost:3000/set
220231
{"msg":"Just trust the Rust"}
221232
```
233+
222234
iron 基本告一段落
223235
当然还有如何使用html模版引擎,那就是直接看文档就行了。
224236

@@ -247,6 +259,7 @@ fn main() {
247259
server.listen("127.0.0.1:6767");
248260
}
249261
```
262+
250263
简单来看,也就是这样回事。
251264

252265
1. 引入了nickel的宏
@@ -276,18 +289,21 @@ fn main() {
276289
}
277290

278291
```
292+
279293
上面的信息你可以编译,使用curl看看发现出现
280294

281295
```
282296
$ curl http://127.0.0.1:6767
283297
Internal Server Error
284298
```
299+
285300
看看文档,没发现什么问题,我紧紧更换了一个文件夹的名字,这个文件夹我也创建了。
286301
然后我在想难道是服务器将目录写死了吗?于是将上面的路径改正这个,问题解决。
287302

288303
```rust
289304
return response.render("examples/assets/template.tpl", &data);
290305
```
306+
291307
我们看一下目录结构
292308

293309
```

attr-and-compiler-arg/rustc-option.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 编译器参数
1+
# 编译器参数
22

33
本章将介绍Rust编译器的参数。
44

0 commit comments

Comments
 (0)