-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
115 changed files
with
620 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
- [初识Rust](1st-glance/README.md) | ||
- [安装Rust](install/preface.md) | ||
- [Linux](install/install_rust_on_linux.md) | ||
- [Mac](install/install_rust_on_mac_os.md) | ||
- [Windows](install/install_rust_on_windows.md) | ||
- [版本管理工具: rustup](install/rustup.md) | ||
- [编辑器](editors/preface.md) | ||
- [前期准备](editors/before.md) | ||
- [vim](editors/vim.md) | ||
- [emacs](editors/emacs.md) | ||
- [vscode](editors/vscode.md) | ||
- [atom](editors/atom.md) | ||
- [sublime](editors/sublime.md) | ||
- [visual studio](editors/visualstudio.md) | ||
- [spacemacs](editors/spacemacs.md) | ||
- [Rust快速入门](quickstart/quickstart.md) | ||
- [Rust旅程](quickstart/rust-travel.md) | ||
- [变量绑定与原生类型](quickstart/primitive-type.md) | ||
- [数组、动态数组和字符串](quickstart/vector-string.md) | ||
- [结构体与枚举](quickstart/struct-enum.md) | ||
- [控制流](quickstart/control-flow.md) | ||
- [函数与方法](quickstart/function-method.md) | ||
- [特性](quickstart/trait.md) | ||
- [注释与文档](quickstart/comments-document.md) | ||
- [输入输出流](quickstart/io-stream.md) | ||
- [Cargo项目管理器](cargo-projects-manager/cargo-projects-manager.md) | ||
- [基本程序结构](flow/preface.md) | ||
- [注释](flow/comment.md) | ||
- [条件](flow/condition.md) | ||
- [循环](flow/repetition.md) | ||
- [类型、运算符和字符串](type/preface.md) | ||
- [基础类型](type/types.md) | ||
- [复合类型](type/compound-types.md) | ||
- [字符串类](type/string.md) | ||
- [基础运算符和字符串格式化](type/operator-and-formatting.md) | ||
- [函数](function/overview.md) | ||
- [函数参数](function/arguement.md) | ||
- [函数返回值](function/return_value.md) | ||
- [语句和表达式](function/statement_expression.md) | ||
- [高阶函数](function/higher_order_function.md) | ||
- [模式匹配](match/overview.md) | ||
- [match关键字](match/match.md) | ||
- [模式 pattern](match/pattern.md) | ||
- [特征 Trait](trait/overview.md) | ||
- [trait关键字](trait/trait.md) | ||
- [trait对象](trait/trait-object.md) | ||
- [泛型](generic/generic.md) | ||
- [可变性、所有权、租借和生命期](ownership-system/ownership_system.md) | ||
- [所有权](ownership-system/ownership.md) | ||
- [引用和借用](ownership-system/borrowing_reference.md) | ||
- [生命周期](ownership-system/lifetime.md) | ||
- [闭包](closure/overview.md) | ||
- [闭包的语法](closure/syntax.md) | ||
- [闭包的实现](closure/implementation.md) | ||
- [闭包作为参数和返回值](closure/as_argument_return_value.md) | ||
- [集合类型 Collections](collections/overview.md) | ||
- [动态数组 Vec](collections/vec.md) | ||
- [哈希表 HashMap](collections/hashmap.md) | ||
- [迭代器](iterator/overview.md) | ||
- [迭代器、适配器、消费者](iterator/iterator.md) | ||
- [模块和包系统、Prelude](module/preface.md) | ||
- [模块 module 和包 crate](module/module.md) | ||
- [Prelude](module/prelude.md) | ||
- [Option、Result与错误处理](error-handling/option-result.md) | ||
- [输入与输出](io/io.md) | ||
- [宏系统](macro/macro.md) | ||
- [堆、栈与Box](heap-stack/heap-stack.md) | ||
- [几种智能指针](rcarc/preface.md) | ||
- [Rc, Arc](rcarc/rcarc.md) | ||
- [Mutex, RwLock](rcarc/mutex.md) | ||
- [Cell, RefCell](rcarc/cell.md) | ||
- [类型系统中的几个常见 Trait](intoborrow/preface.md) | ||
- [Into/From 及其在 String 和 &str 互转上的应用](intoborrow/into.md) | ||
- [AsRef, AsMut](intoborrow/asref.md) | ||
- [Borrow, BorrowMut, ToOwned](intoborrow/borrow.md) | ||
- [Deref 与 Deref coercions](intoborrow/deref.md) | ||
- [Cow 及其在 String 和 &str 上的应用](intoborrow/cow.md) | ||
- [Send 和 Sync](marker/sendsync.md) | ||
- [并发,并行,多线程编程](concurrency-parallel-thread/preface.md) | ||
- [线程](concurrency-parallel-thread/thread.md) | ||
- [消息传递](concurrency-parallel-thread/message-passing.md) | ||
- [共享内存](concurrency-parallel-thread/share-memory.md) | ||
- [同步](concurrency-parallel-thread/synchronize.md) | ||
- [并行](concurrency-parallel-thread/parallel.md) | ||
- [Unsafe、原始指针](unsafe-rawpointer/preface.md) | ||
- [Unsafe](unsafe-rawpointer/unsafe.md) | ||
- [原始指针](unsafe-rawpointer/raw-pointer.md) | ||
- [FFI](ffi/preface.md) | ||
- [rust调用ffi函数](ffi/calling-ffi-function.md) | ||
- [将rust编译成库](ffi/compiling-rust-to-lib.md) | ||
- [运算符重载](operator-overloading/operator.md) | ||
- [属性和编译器参数](attr-and-compiler-arg/preface.md) | ||
- [属性](attr-and-compiler-arg/attribute.md) | ||
- [编译器参数](attr-and-compiler-arg/rustc-option.md) | ||
- [Cargo参数配置](cargo-detailed-cfg/cargo-detailed-cfg.md) | ||
- [测试与评测](testing/preface.md) | ||
- [测试 (testing)](testing/threearchtest.md) | ||
- [评测 (benchmark)](testing/bench.md) | ||
- [代码风格](coding-style/style.md) | ||
- [Any与反射](any/any.md) | ||
- [安全(safe)](safe/safety.md) | ||
- [常用数据结构实现](data-structure/preface.md) | ||
- [栈结构](data-structure/stack.md) | ||
- [队列](data-structure/queue.md) | ||
- [二叉树](data-structure/binary_tree.md) | ||
- [优先队列](data-structure/priority_queue.md) | ||
- [链表](data-structure/linked_list.md) | ||
- [图结构](data-structure/graph.md) | ||
- [标准库介绍](std/overview.md) | ||
- [系统命令:调用grep](std/process.md) | ||
- [目录操作:简单grep](std/fs-and-path.md) | ||
- [网络模块:W回音](std/net.md) | ||
- [实战篇](action/preface.md) | ||
- [实战:Json处理](action/json_data/readme.md) | ||
- [实战:Web 应用开发入门](action/mysite/readme.md) | ||
- [实战:使用Postgresql数据库](action/db/readme.md) | ||
- [附录-术语表](appendix/glossary.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,13 @@ json是一种比较重要的格式,尤其是现在的web开发领域,json相 | |
rust中的json处理依赖 cargo 中的rustc-serialize模块 | ||
|
||
###先简单的创建一个rust项目工程 | ||
|
||
``` rust | ||
$ cargo new json_data --bin | ||
``` | ||
|
||
生成文件树: | ||
|
||
```shell | ||
vagrant@ubuntu-14:~/tmp/test/rustprimer$ tree | ||
. | ||
|
@@ -19,6 +22,7 @@ vagrant@ubuntu-14:~/tmp/test/rustprimer$ tree | |
``` | ||
|
||
生成项目`json_data`,项目下文件介绍: | ||
|
||
- Caogo.toml ,文件中填写一些项目的相关信息,比如版本号,联系人,项目名,文件的内容如下: | ||
|
@@ -39,6 +43,7 @@ authors = ["wangxxx <[email protected]>"] | |
|
||
rustc-serialize 这个是第三方的模块,需要从[cargo](https://crates.io/crates/rustc-serialize)下载。 | ||
下载很简单,只需修改一下cargo.toml文件就行了. | ||
|
||
```toml | ||
[package] | ||
name = "json_data" | ||
|
@@ -49,12 +54,16 @@ authors = ["wangxxx <[email protected]>"] | |
rustc-serialize = "0.3.18" | ||
``` | ||
|
||
然后执行在当前目录执行: | ||
|
||
``` | ||
$ cargo build | ||
``` | ||
*注意一个问题由于国内网络访问github不稳定,这些第三方库很多托管在github上,所以可能需要修改你的 | ||
网络访问* | ||
1. 在安装rust之后,会在你的用户目录之下生成一个`.cargo`文件夹,进入这个文件夹 | ||
2. 在`.cargo`文件夹下,创建一个`config`文件,在文件中填写中科大软件源,可能以后会出现其他的源,先用这个 | ||
3. `config`文件内容如下 | ||
|
@@ -64,6 +73,7 @@ $ cargo build | |
index = "git://crates.mirrors.ustc.edu.cn/index" | ||
``` | ||
|
||
cargo build 执行之后的提示信息 | ||
|
||
``` | ||
|
@@ -72,6 +82,7 @@ cargo build 执行之后的提示信息 | |
Compiling rustc-serialize v0.3.18 (registry git://crates.mirrors.ustc.edu.cn/index) | ||
Compiling json_data v0.1.0 (file:///home/vagrant/tmp/test/rustprimer/json_data) | ||
``` | ||
|
||
再次执行tree命令: | ||
|
||
``` | ||
|
@@ -90,6 +101,7 @@ cargo build 执行之后的提示信息 | |
`-- native | ||
``` | ||
|
||
可以看到多了很多文件,重点关注`cargo.lock`,开打文件: | ||
|
||
```toml | ||
|
@@ -106,9 +118,11 @@ version = "0.3.18" | |
source = "registry+git://crates.mirrors.ustc.edu.cn/index" | ||
|
||
``` | ||
|
||
是关于项目编译的一些依赖信息 | ||
|
||
还有生成了target文件夹,生成了可执行文件json_data,因为main.rs中的执行结果就是打印`hello world` | ||
|
||
``` | ||
$ cargo run | ||
|
@@ -152,4 +166,5 @@ fn main() { | |
} | ||
|
||
``` | ||
|
||
当然我们也可以在文本中作为api的返回结果使用,下来的章节中,我们将讨论这个问题 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
## 编译器参数 | ||
# 编译器参数 | ||
|
||
本章将介绍Rust编译器的参数。 | ||
|
||
|
Oops, something went wrong.