Skip to content

Commit 0664eb3

Browse files
author
lkchen-x1c
committed
Merge remote-tracking branch 'refs/remotes/rustcc/master'
2 parents 7ab516e + 897fb63 commit 0664eb3

File tree

133 files changed

+1447
-382
lines changed

Some content is hidden

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

133 files changed

+1447
-382
lines changed

1st-glance/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,43 @@ Rust 运行在以下操作系统上:Linux, OS X, Windows, FreeBSD, Android, iO
5454
- [Liqueur Librazy](https://github.com/Librazy)
5555
- [Knight42](https://github.com/knight42)
5656
- [Ryan Kung](https://github.com/ryankung)
57+
- lambdaplus
58+
- doomsplayer
59+
- lucklove
60+
- veekxt
61+
- lk-chen
62+
- RyanKung
63+
- arrowrowe
64+
- marvin-min
65+
- ghKelo
66+
- wy193777
67+
- domty
68+
- xusss
69+
- wangyu190810
70+
- nextzhou
71+
- zhongke
72+
- [ryuki](https://github.com/3442853561)
73+
- codeworm96
74+
- anzhihun
75+
- lidashuang
76+
- sceext2
77+
- loggerhead
78+
- twq0076262
79+
- passchaos
80+
- yyrust
81+
- markgeek
82+
- ts25504
83+
- overvenus
84+
- Akagi201
85+
- theJian
86+
- jqs7
87+
- ahjdzx
88+
- chareice
89+
- chenshaobo
90+
- marvinguo
91+
- izgzhen
92+
- ziqin
93+
- peng1999
5794

5895
等。在此,向他们的辛苦工作和无私奉献表示尊敬和感谢!
5996

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
我们欢迎RustPrimer的Contributor们将自己的 `[blog/github/社交帐号]`
2+
添加在 [1st-glance/README.md](./1st-glance/README.md)里。
3+
但严禁未参与者恶意添加帐号,违者将会被永久拒绝PR和issue权限。

README.md

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

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

1112
## 在线阅读地址
1213

13-
[点我阅读](https://wayslog.gitbooks.io/rustprimer/content/)
14+
[点我阅读](https://rustcc.gitbooks.io/rustprimer/content/)
1415

1516
也可复制以下链接:
1617

1718
```
18-
https://wayslog.gitbooks.io/rustprimer/content/
19+
https://rustcc.gitbooks.io/rustprimer/content/
1920
```
2021

2122
## 社区
@@ -52,11 +53,6 @@ gitbook serve
5253

5354
即可。
5455

55-
56-
## 成为Contributors
57-
58-
我们欢迎RustPrimer的Contributor们将自己的 `[blog/github/社交帐号]` 添加在 [1st-glance/README.md](./1st-glance/README.md)里。但严禁未参与者恶意添加帐号,违者将会被永久拒绝PR和issue权限。
59-
6056
## ChangeLog
6157

6258
1. 2016年3月31日,初稿完成。发布 v1.0 版。

SUMMARY.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
* [trait关键字](trait/trait.md)
4848
* [trait对象](trait/trait-object.md)
4949
* [泛型](generic/generic.md)「stormgbs」
50-
* [可变性、所有权、租借和生命期](ownership-system/ownership_system.md)「stormgbs」
50+
* [可变性、所有权、租借和生命期](ownership-system/preface.md)「stormgbs」
5151
* [所有权](ownership-system/ownership.md)
5252
* [引用和借用](ownership-system/borrowing_reference.md)
5353
* [生命周期](ownership-system/lifetime.md)
@@ -63,8 +63,12 @@
6363
* [模块和包系统、Prelude](module/preface.md)「daogangtang」
6464
* [模块 module 和包 crate](module/module.md)
6565
* [Prelude](module/prelude.md)
66+
* [pub restricted](module/pub-restricted.md)
6667
* [Option、Result与错误处理](error-handling/option-result.md)「JohnSmithX」
67-
* [输入与输出](io/io.md)「tennix」
68+
* [输入与输出](io/preface.md)
69+
 * [标准输入输出](io/io.md)
70+
 * [print! 宏](io/output.md)
71+
 * [文件输入输出](io/file-io.md)「tennix」
6872
* [宏系统](macro/macro.md)「tennix」
6973
* [堆、栈与Box](heap-stack/heap-stack.md)「tennix」
7074
* [几种智能指针](rcarc/preface.md)「daogangtang」
@@ -100,7 +104,7 @@
100104
* [评测 (benchmark)](testing/bench.md)
101105
* [代码风格](coding-style/style.md)「tiansiyuan」
102106
* [Any与反射](any/any.md)「wayslog」
103-
* [安全(safe)](safe/safety.md)「daogangtang」
107+
* [安全](safe/safety.md)「daogangtang」
104108
* [常用数据结构实现](data-structure/preface.md)「Naupio」
105109
* [栈结构](data-structure/stack.md)
106110
* [队列](data-structure/queue.md)

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: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# rust数据库操作
22

3-
编程时,我们依赖数据库来存储相应的数据,很多编程语言都支持对数据库的操作(为什么不是全部,因为还有html这样的东西),所以当然
4-
可以使用rust操作数据库。
3+
编程时,我们依赖数据库来存储相应的数据,很多编程语言都支持对数据库的操作,所以当然可以使用Rust操作数据库。
54

6-
不过在我自己操作时,发现很多问题,主要因为我不了解rust在操作数据库时,应该注意的事情,从而浪费了很多的时间,在进行数据查询时。
5+
不过在我自己操作时,发现很多问题,主要因为我不了解Rust在操作数据库时,应该注意的事情,从而浪费了很多的时间,在进行数据查询时。
76
具体遇到的坑,我会做一些演示,从而让大家避免这些情况。
87

9-
首先使用rust操作postgresql,因为postgresql是我最喜欢的数据库
8+
首先使用Rust操作PostgreSQL,因为PostgreSQL是我最喜欢的数据库
109

1110
首先创建新项目 `cargo new db --bin`
1211

13-
在cargo.toml中添加,postgres:
12+
在cargo.toml中添加 `postgres` 如下:
13+
1414

1515
``` rust
1616
[package]
@@ -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,14 +183,15 @@ fn main() {
182183
```
183184

184185
自己遇到的坑
186+
185187
- 创建连接函数时,连接必须有一个返回值,所以必须指定返回值的类型,
186-
对于一个写python的人而言,我觉得是痛苦的,我想按照官方的写法match
188+
对于一个写Python的人而言,我觉得是痛苦的,我想按照官方的写法match
187189
一下,发现可能产生多个返回值。在编译时直接无法通过编译,所以最终
188190
使用了unwrap,解决问题,不过我还是没有学会,函数多值返回时我如何
189191
定义返回值
190192

191-
- 在使用`&conn.query(query,&[]).unwrap()`时,我按照文档操作,文档
192-
说返回的是一个可迭代的数据,那也就是说,我可以使用for循环,将数据打印,
193+
- 在使用`&conn.query(query,&[]).unwrap()`时,我按照文档操作,文档说
194+
返回的是一个可迭代的数据,那也就是说,我可以使用for循环,将数据打印,
193195
但是发现怎么也不能实现:
194196

195197
``` rust
@@ -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)
@@ -216,13 +220,14 @@ src/lib.rs:53:37: 53:47 help: run `rustc --explain E0282` to see a detailed expl
216220
error: aborting due to previous error
217221
Could not compile `db`.
218222

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

222-
可能自己眼高手低,如果从头再把rust的相关教程看一下,可能很早就发现这个问题,
223-
也有可能是因为习惯了写python,导致自己使用固有的思维来看待问题和钻牛角尖,才
227+
可能自己眼高手低,如果从头再把Rust的相关教程看一下,可能很早就发现这个问题,
228+
也有可能是因为习惯了写Python,导致自己使用固有的思维来看待问题和钻牛角尖,才
224229
导致出现这样的问题,浪费很多的时间。
225230

226231
- 改变思维,把自己当作一个全新的新手,既要利用已有的思想来学习新的语言,同样不要
227-
被自己很精通的语言,固话自己的思维
232+
被自己很精通的语言,固化自己的思维
228233

0 commit comments

Comments
 (0)