diff --git a/.DS_Store b/.DS_Store index 1c840f6..e16b619 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Readme.md b/Readme.md index b73421a..20489b6 100644 --- a/Readme.md +++ b/Readme.md @@ -1 +1,28 @@ # Rust exercise +Greetings and welcome to `exercise.rs`,here you can find bunch of easy to hard exercises to improve your Rust skills,this will help you fill the gap of easy-to-learn and hard-to-use. + +## Online Reading +This book is written in English and Chinese, you can pick up the language you are familiar with: +- English: [https://exercise.rs](https://exercise.rs) +- 简体中文: [https://zh.exercise.rs](https://zh.=[exercise.rs) + +## Learning Rust +If you are a first-time Rust learner, here are some high quality learning resources : +- [The Book](https://doc.rust-lang.org/book/index.html) for English speakers +- [Rust语言圣经(The Course)](https://course.rs) for Chinese speakers, it covers nearly all the topics in Rust + + +## difference to rustlings +[Rustlings](https://github.com/rust-lang/rustlings) only contains small and easy exercises for junior rust devs. There is a big gap between learning Rust and using it in your projects. + +Another limit for rustlings is that you have to download rustlings to local machine and compile it first before starting to learn. + +## difference to rust by example +[Rust By Example](https://doc.rust-lang.org/stable/rust-by-example/) is an excellent online book for learning Rust,`exercise.rs` has some small advantages in : + +- more topics and exercises,specially for the hard part of Rust,e.g lifetime、smart pointers、threads 、async/.await etc +- difficulty from easy to hard,it will minimize the gap between learning and using in projects +- up-to-date, e.g features which added in Rust 1.58 also have the corresponding exercises in `exercise.rs` +- Both `course.rs` and `exercise.rs` are designed according to the CS courses in college,so quliaty is the most important factor + + diff --git a/.gitignore b/en/.gitignore similarity index 100% rename from .gitignore rename to en/.gitignore diff --git a/assets/CNAME b/en/assets/CNAME similarity index 100% rename from assets/CNAME rename to en/assets/CNAME diff --git a/book.toml b/en/book.toml similarity index 93% rename from book.toml rename to en/book.toml index 5d2954b..7ec5b17 100644 --- a/book.toml +++ b/en/book.toml @@ -10,10 +10,11 @@ editor = "ace" [output.html.fold] enable = true +level = 1 [output.html] git-repository-url = "https://github.com/sunface/rust-exercise" -edit-url-template = "https://github.com/sunface/rust-exercise/edit/master/{path}" +edit-url-template = "https://github.com/sunface/rust-exercise/edit/master/en/{path}" [rust] edition = "2021" \ No newline at end of file diff --git a/deploy b/en/deploy similarity index 100% rename from deploy rename to en/deploy diff --git a/src/SUMMARY.md b/en/src/SUMMARY.md similarity index 100% rename from src/SUMMARY.md rename to en/src/SUMMARY.md diff --git a/src/async/async-await.md b/en/src/async/async-await.md similarity index 100% rename from src/async/async-await.md rename to en/src/async/async-await.md diff --git a/src/async/future.md b/en/src/async/future.md similarity index 100% rename from src/async/future.md rename to en/src/async/future.md diff --git a/src/async/intro.md b/en/src/async/intro.md similarity index 100% rename from src/async/intro.md rename to en/src/async/intro.md diff --git a/src/async/pin-unpin.md b/en/src/async/pin-unpin.md similarity index 100% rename from src/async/pin-unpin.md rename to en/src/async/pin-unpin.md diff --git a/src/async/stream.md b/en/src/async/stream.md similarity index 100% rename from src/async/stream.md rename to en/src/async/stream.md diff --git a/src/basic-types/char-bool-unit.md b/en/src/basic-types/char-bool-unit.md similarity index 100% rename from src/basic-types/char-bool-unit.md rename to en/src/basic-types/char-bool-unit.md diff --git a/src/basic-types/functions.md b/en/src/basic-types/functions.md similarity index 100% rename from src/basic-types/functions.md rename to en/src/basic-types/functions.md diff --git a/src/basic-types/intro.md b/en/src/basic-types/intro.md similarity index 100% rename from src/basic-types/intro.md rename to en/src/basic-types/intro.md diff --git a/src/basic-types/numbers.md b/en/src/basic-types/numbers.md similarity index 100% rename from src/basic-types/numbers.md rename to en/src/basic-types/numbers.md diff --git a/src/basic-types/statements-expressions.md b/en/src/basic-types/statements-expressions.md similarity index 100% rename from src/basic-types/statements-expressions.md rename to en/src/basic-types/statements-expressions.md diff --git a/src/circle-refer b/en/src/circle-refer similarity index 100% rename from src/circle-refer rename to en/src/circle-refer diff --git a/src/circle-reference/intro.md b/en/src/circle-reference/intro.md similarity index 100% rename from src/circle-reference/intro.md rename to en/src/circle-reference/intro.md diff --git a/src/collections/hashmap.md b/en/src/collections/hashmap.md similarity index 100% rename from src/collections/hashmap.md rename to en/src/collections/hashmap.md diff --git a/src/collections/intro.md b/en/src/collections/intro.md similarity index 100% rename from src/collections/intro.md rename to en/src/collections/intro.md diff --git a/src/collections/vector.md b/en/src/collections/vector.md similarity index 100% rename from src/collections/vector.md rename to en/src/collections/vector.md diff --git a/src/comments-docs.md b/en/src/comments-docs.md similarity index 100% rename from src/comments-docs.md rename to en/src/comments-docs.md diff --git a/src/compound-types/array.md b/en/src/compound-types/array.md similarity index 100% rename from src/compound-types/array.md rename to en/src/compound-types/array.md diff --git a/src/compound-types/enum.md b/en/src/compound-types/enum.md similarity index 100% rename from src/compound-types/enum.md rename to en/src/compound-types/enum.md diff --git a/src/compound-types/intro.md b/en/src/compound-types/intro.md similarity index 100% rename from src/compound-types/intro.md rename to en/src/compound-types/intro.md diff --git a/src/compound-types/string-slice.md b/en/src/compound-types/string-slice.md similarity index 100% rename from src/compound-types/string-slice.md rename to en/src/compound-types/string-slice.md diff --git a/src/compound-types/struct.md b/en/src/compound-types/struct.md similarity index 100% rename from src/compound-types/struct.md rename to en/src/compound-types/struct.md diff --git a/src/compound-types/tuple.md b/en/src/compound-types/tuple.md similarity index 100% rename from src/compound-types/tuple.md rename to en/src/compound-types/tuple.md diff --git a/src/crate b/en/src/crate similarity index 100% rename from src/crate rename to en/src/crate diff --git a/src/crate-module/crate.md b/en/src/crate-module/crate.md similarity index 100% rename from src/crate-module/crate.md rename to en/src/crate-module/crate.md diff --git a/src/crate-module/intro.md b/en/src/crate-module/intro.md similarity index 100% rename from src/crate-module/intro.md rename to en/src/crate-module/intro.md diff --git a/src/crate-module/module.md b/en/src/crate-module/module.md similarity index 100% rename from src/crate-module/module.md rename to en/src/crate-module/module.md diff --git a/src/crate-module/use-pub.md b/en/src/crate-module/use-pub.md similarity index 100% rename from src/crate-module/use-pub.md rename to en/src/crate-module/use-pub.md diff --git a/src/errors.md b/en/src/errors.md similarity index 100% rename from src/errors.md rename to en/src/errors.md diff --git a/src/flow-control.md b/en/src/flow-control.md similarity index 100% rename from src/flow-control.md rename to en/src/flow-control.md diff --git a/src/formatted-output.md b/en/src/formatted-output.md similarity index 100% rename from src/formatted-output.md rename to en/src/formatted-output.md diff --git a/src/functional-programing/cloure.md b/en/src/functional-programing/cloure.md similarity index 100% rename from src/functional-programing/cloure.md rename to en/src/functional-programing/cloure.md diff --git a/src/functional-programing/intro.md b/en/src/functional-programing/intro.md similarity index 100% rename from src/functional-programing/intro.md rename to en/src/functional-programing/intro.md diff --git a/src/functional-programing/iterator.md b/en/src/functional-programing/iterator.md similarity index 100% rename from src/functional-programing/iterator.md rename to en/src/functional-programing/iterator.md diff --git a/src/functional-programming/closure.md b/en/src/functional-programming/closure.md similarity index 100% rename from src/functional-programming/closure.md rename to en/src/functional-programming/closure.md diff --git a/src/functional-programming/intro.md b/en/src/functional-programming/intro.md similarity index 100% rename from src/functional-programming/intro.md rename to en/src/functional-programming/intro.md diff --git a/src/generics-traits/advance-traits.md b/en/src/generics-traits/advance-traits.md similarity index 100% rename from src/generics-traits/advance-traits.md rename to en/src/generics-traits/advance-traits.md diff --git a/src/generics-traits/generics.md b/en/src/generics-traits/generics.md similarity index 100% rename from src/generics-traits/generics.md rename to en/src/generics-traits/generics.md diff --git a/src/generics-traits/intro.md b/en/src/generics-traits/intro.md similarity index 100% rename from src/generics-traits/intro.md rename to en/src/generics-traits/intro.md diff --git a/src/generics-traits/trait-object.md b/en/src/generics-traits/trait-object.md similarity index 100% rename from src/generics-traits/trait-object.md rename to en/src/generics-traits/trait-object.md diff --git a/src/generics-traits/traits.md b/en/src/generics-traits/traits.md similarity index 100% rename from src/generics-traits/traits.md rename to en/src/generics-traits/traits.md diff --git a/src/global-variables.md b/en/src/global-variables.md similarity index 100% rename from src/global-variables.md rename to en/src/global-variables.md diff --git a/src/lifetime/advance.md b/en/src/lifetime/advance.md similarity index 100% rename from src/lifetime/advance.md rename to en/src/lifetime/advance.md diff --git a/src/lifetime/basic.md b/en/src/lifetime/basic.md similarity index 100% rename from src/lifetime/basic.md rename to en/src/lifetime/basic.md diff --git a/src/lifetime/intro.md b/en/src/lifetime/intro.md similarity index 100% rename from src/lifetime/intro.md rename to en/src/lifetime/intro.md diff --git a/src/lifetime/static.md b/en/src/lifetime/static.md similarity index 100% rename from src/lifetime/static.md rename to en/src/lifetime/static.md diff --git a/src/macro.md b/en/src/macro.md similarity index 100% rename from src/macro.md rename to en/src/macro.md diff --git a/src/method.md b/en/src/method.md similarity index 100% rename from src/method.md rename to en/src/method.md diff --git a/src/newtype-sized.md b/en/src/newtype-sized.md similarity index 100% rename from src/newtype-sized.md rename to en/src/newtype-sized.md diff --git a/src/ownership/borrowing.md b/en/src/ownership/borrowing.md similarity index 100% rename from src/ownership/borrowing.md rename to en/src/ownership/borrowing.md diff --git a/src/ownership/intro.md b/en/src/ownership/intro.md similarity index 100% rename from src/ownership/intro.md rename to en/src/ownership/intro.md diff --git a/src/ownership/ownership.md b/en/src/ownership/ownership.md similarity index 100% rename from src/ownership/ownership.md rename to en/src/ownership/ownership.md diff --git a/src/pattern-match/intro.md b/en/src/pattern-match/intro.md similarity index 100% rename from src/pattern-match/intro.md rename to en/src/pattern-match/intro.md diff --git a/src/pattern-match/match-iflet.md b/en/src/pattern-match/match-iflet.md similarity index 100% rename from src/pattern-match/match-iflet.md rename to en/src/pattern-match/match-iflet.md diff --git a/src/pattern-match/option.md b/en/src/pattern-match/option.md similarity index 100% rename from src/pattern-match/option.md rename to en/src/pattern-match/option.md diff --git a/src/pattern-match/patterns.md b/en/src/pattern-match/patterns.md similarity index 100% rename from src/pattern-match/patterns.md rename to en/src/pattern-match/patterns.md diff --git a/src/resu b/en/src/resu similarity index 100% rename from src/resu rename to en/src/resu diff --git a/src/result-panic/intro.md b/en/src/result-panic/intro.md similarity index 100% rename from src/result-panic/intro.md rename to en/src/result-panic/intro.md diff --git a/src/result-panic/panic.md b/en/src/result-panic/panic.md similarity index 100% rename from src/result-panic/panic.md rename to en/src/result-panic/panic.md diff --git a/src/result-panic/result.md b/en/src/result-panic/result.md similarity index 100% rename from src/result-panic/result.md rename to en/src/result-panic/result.md diff --git a/src/self-referential.md b/en/src/self-referential.md similarity index 100% rename from src/self-referential.md rename to en/src/self-referential.md diff --git a/src/smart-pointers/box.md b/en/src/smart-pointers/box.md similarity index 100% rename from src/smart-pointers/box.md rename to en/src/smart-pointers/box.md diff --git a/src/smart-pointers/cell-refcell.md b/en/src/smart-pointers/cell-refcell.md similarity index 100% rename from src/smart-pointers/cell-refcell.md rename to en/src/smart-pointers/cell-refcell.md diff --git a/src/smart-pointers/deref.md b/en/src/smart-pointers/deref.md similarity index 100% rename from src/smart-pointers/deref.md rename to en/src/smart-pointers/deref.md diff --git a/src/smart-pointers/drop.md b/en/src/smart-pointers/drop.md similarity index 100% rename from src/smart-pointers/drop.md rename to en/src/smart-pointers/drop.md diff --git a/src/smart-pointers/intro.md b/en/src/smart-pointers/intro.md similarity index 100% rename from src/smart-pointers/intro.md rename to en/src/smart-pointers/intro.md diff --git a/src/smart-pointers/rc-arc.md b/en/src/smart-pointers/rc-arc.md similarity index 100% rename from src/smart-pointers/rc-arc.md rename to en/src/smart-pointers/rc-arc.md diff --git a/src/tests/assertions.md b/en/src/tests/assertions.md similarity index 100% rename from src/tests/assertions.md rename to en/src/tests/assertions.md diff --git a/src/tests/benchmark.md b/en/src/tests/benchmark.md similarity index 100% rename from src/tests/benchmark.md rename to en/src/tests/benchmark.md diff --git a/src/tests/intro.md b/en/src/tests/intro.md similarity index 100% rename from src/tests/intro.md rename to en/src/tests/intro.md diff --git a/src/tests/unit-integration.md b/en/src/tests/unit-integration.md similarity index 100% rename from src/tests/unit-integration.md rename to en/src/tests/unit-integration.md diff --git a/src/tests/write-tests.md b/en/src/tests/write-tests.md similarity index 100% rename from src/tests/write-tests.md rename to en/src/tests/write-tests.md diff --git a/src/threads/atomic.md b/en/src/threads/atomic.md similarity index 100% rename from src/threads/atomic.md rename to en/src/threads/atomic.md diff --git a/src/threads/basic-using.md b/en/src/threads/basic-using.md similarity index 100% rename from src/threads/basic-using.md rename to en/src/threads/basic-using.md diff --git a/src/threads/intro.md b/en/src/threads/intro.md similarity index 100% rename from src/threads/intro.md rename to en/src/threads/intro.md diff --git a/src/threads/message-passing.md b/en/src/threads/message-passing.md similarity index 100% rename from src/threads/message-passing.md rename to en/src/threads/message-passing.md diff --git a/src/threads/send-sync.md b/en/src/threads/send-sync.md similarity index 100% rename from src/threads/send-sync.md rename to en/src/threads/send-sync.md diff --git a/src/threads/sync.md b/en/src/threads/sync.md similarity index 100% rename from src/threads/sync.md rename to en/src/threads/sync.md diff --git a/src/type-conversion.md b/en/src/type-conversion.md similarity index 100% rename from src/type-conversion.md rename to en/src/type-conversion.md diff --git a/src/unsafe.md b/en/src/unsafe.md similarity index 100% rename from src/unsafe.md rename to en/src/unsafe.md diff --git a/src/variables.md b/en/src/variables.md similarity index 100% rename from src/variables.md rename to en/src/variables.md diff --git a/src/weak.md b/en/src/weak.md similarity index 100% rename from src/weak.md rename to en/src/weak.md diff --git a/src/why-exercise.md b/en/src/why-exercise.md similarity index 100% rename from src/why-exercise.md rename to en/src/why-exercise.md diff --git a/zh-CN/.gitignore b/zh-CN/.gitignore new file mode 100644 index 0000000..7585238 --- /dev/null +++ b/zh-CN/.gitignore @@ -0,0 +1 @@ +book diff --git a/zh-CN/assets/CNAME b/zh-CN/assets/CNAME new file mode 100644 index 0000000..2c5ea12 --- /dev/null +++ b/zh-CN/assets/CNAME @@ -0,0 +1 @@ +exercise.rs \ No newline at end of file diff --git a/zh-CN/book.toml b/zh-CN/book.toml new file mode 100644 index 0000000..75b13d7 --- /dev/null +++ b/zh-CN/book.toml @@ -0,0 +1,20 @@ +[book] +title = "Rust Exercise" +description = "A set of exercises and examples to pratice various aspects of Rust, also for the rust course (book) at https://course.rs" +authors = ["sunface, https://im.dev"] +language = "en" + +[output.html.playpen] +editable = true +editor = "ace" + +[output.html.fold] +enable = true +level = 1 + +[output.html] +git-repository-url = "https://github.com/sunface/rust-exercise" +edit-url-template = "https://github.com/sunface/rust-exercise/edit/master/zh-CN/{path}" + +[rust] +edition = "2021" \ No newline at end of file diff --git a/zh-CN/deploy b/zh-CN/deploy new file mode 100755 index 0000000..c1c7896 --- /dev/null +++ b/zh-CN/deploy @@ -0,0 +1,21 @@ +## this script deploys the static website of course.rs to github pages + +## build static website for book +mdbook build +## copy CNAME info to book dir +cp ./assets/CNAME ./book/ +cp ./assets/*.html ./book/ +cp ./assets/sitemap.xml ./book/ + +## init git repo +cd book +git init +git config user.name "sunface" +git config user.email "cto@188.com" +git add . +git commit -m 'deploy' +git branch -M gh-pages +git remote add origin https://github.com/sunface/rust-exercise + +## push to github pages +git push -u -f origin gh-pages \ No newline at end of file diff --git a/zh-CN/src/SUMMARY.md b/zh-CN/src/SUMMARY.md new file mode 100644 index 0000000..e829ac1 --- /dev/null +++ b/zh-CN/src/SUMMARY.md @@ -0,0 +1,78 @@ +# Summary + +- [关于 exercise.rs](why-exercise.md) +- [变量绑定与解构 todo](variables.md) +- [基本类型 todo](basic-types/intro.md) + - [数值类型](basic-types/numbers.md) + - [字符、布尔、单元类型](basic-types/char-bool-unit.md) + - [语句与表达式](basic-types/statements-expressions.md) + - [函数](basic-types/functions.md) +- [所有权和借用 todo](ownership/intro.md) + - [所有权](ownership/ownership.md) + - [引用和借用](ownership/borrowing.md) +- [复合类型 todo](compound-types/intro.md) + - [字符串与切片](compound-types/string-slice.md) + - [元组](compound-types/tuple.md) + - [结构体](compound-types/struct.md) + - [枚举](compound-types/enum.md) + - [数组](compound-types/array.md) +- [流程控制 todo](flow-control.md) +- [模式匹配 todo](pattern-match/intro.md) + - [match 和 if let](pattern-match/match-iflet.md) + - [解构 Option](pattern-match/option.md) + - [模式](pattern-match/patterns.md) +- [方法 Method todo](method.md) +- [泛型和特征 todo](generics-traits/intro.md) + - [泛型 Generics](generics-traits/generics.md) + - [特征 Traits](generics-traits/traits.md) + - [特征对象](generics-traits/trait-object.md) + - [进一步深入特征](generics-traits/advance-traits.md) +- [集合类型 todo](collections/intro.md) + - [动态数组 Vector](collections/vector.md) + - [KV 存储 HashMap](collections/hashmap.md) +- [类型转换 todo](type-conversion.md) +- [返回值和 panic! todo](result-panic/intro.md) + - [panic! 深入剖析](result-panic/panic.md) + - [返回值result 和 ?](result-panic/result.md) +- [包和模块 todo](crate-module/intro.md) + - [包 Crate](crate-module/crate.md) + - [模块 Module](crate-module/module.md) + - [使用use引入模块及受限可见性](crate-module/use-pub.md) +- [注释和文档 todo](comments-docs.md) +- [格式化输出 todo](formatted-output.md) +- [生命周期 todo](lifetime/intro.md) + - [生命周期基础](lifetime/basic.md) + - [&'static 和 T: 'static](lifetime/static.md) + - [深入生命周期](lifetime/advance.md) +- [函数式编程: 闭包、迭代器 todo](functional-programing/intro.md) + - [闭包 Closure](functional-programing/cloure.md) + - [迭代器 Iterator](functional-programing/iterator.md) +- [newtype 和 Sized todo](newtype-sized.md) +- [智能指针 todo](smart-pointers/intro.md) + - [Box](smart-pointers/box.md) + - [Deref](smart-pointers/deref.md) + - [Drop](smart-pointers/drop.md) + - [Rc and Arc](smart-pointers/rc-arc.md) + - [Cell and RefCell](smart-pointers/cell-refcell.md) +- [Weak 和循环引用todo](weak.md) +- [自引用 todo](self-referential.md) +- [多线程 todo](threads/intro.md) + - [多线程基础](threads/basic-using.md) + - [消息传递](threads/message-passing.md) + - [线程同步:锁、Condvar和信号量](threads/sync.md) + - [线程同步:Atomic](threads/atomic.md) + - [Send 和 Sync](threads/send-sync.md) +- [全局变量 todo](global-variables.md) +- [错误处理 todo](errors.md) +- [unsafe todo](unsafe.md) +- [macro 宏 todo](macro.md) +- [测试 todo](tests/intro.md) + - [编写测试及控制执行](tests/write-tests.md) + - [基准性能测试 Benchmark](tests/benchmark.md) + - [单元测试及集成测试](tests/unit-integration.md) + - [断言 Assertions](tests/assertions.md) +- [Async/Await 异步编程 todo](async/intro.md) + - [async 和 await!](async/async-await.md) + - [Future](async/future.md) + - [Pin 和 Unpin](async/pin-unpin.md) + - [Stream 流处理](async/stream.md) diff --git a/zh-CN/src/async/async-await.md b/zh-CN/src/async/async-await.md new file mode 100644 index 0000000..a20c0b8 --- /dev/null +++ b/zh-CN/src/async/async-await.md @@ -0,0 +1 @@ +# async and await! diff --git a/zh-CN/src/async/future.md b/zh-CN/src/async/future.md new file mode 100644 index 0000000..5f24b0e --- /dev/null +++ b/zh-CN/src/async/future.md @@ -0,0 +1 @@ +# Future diff --git a/zh-CN/src/async/intro.md b/zh-CN/src/async/intro.md new file mode 100644 index 0000000..70bdb9f --- /dev/null +++ b/zh-CN/src/async/intro.md @@ -0,0 +1 @@ +# Async/Await diff --git a/zh-CN/src/async/pin-unpin.md b/zh-CN/src/async/pin-unpin.md new file mode 100644 index 0000000..8655bd1 --- /dev/null +++ b/zh-CN/src/async/pin-unpin.md @@ -0,0 +1 @@ +# Pin and Unpin diff --git a/zh-CN/src/async/stream.md b/zh-CN/src/async/stream.md new file mode 100644 index 0000000..867bd88 --- /dev/null +++ b/zh-CN/src/async/stream.md @@ -0,0 +1 @@ +# Stream diff --git a/zh-CN/src/basic-types/char-bool-unit.md b/zh-CN/src/basic-types/char-bool-unit.md new file mode 100644 index 0000000..b406dee --- /dev/null +++ b/zh-CN/src/basic-types/char-bool-unit.md @@ -0,0 +1 @@ +# Char, Bool and Unit diff --git a/zh-CN/src/basic-types/functions.md b/zh-CN/src/basic-types/functions.md new file mode 100644 index 0000000..0c5faf5 --- /dev/null +++ b/zh-CN/src/basic-types/functions.md @@ -0,0 +1 @@ +# Functions diff --git a/zh-CN/src/basic-types/intro.md b/zh-CN/src/basic-types/intro.md new file mode 100644 index 0000000..2d47759 --- /dev/null +++ b/zh-CN/src/basic-types/intro.md @@ -0,0 +1 @@ +# Basic Types diff --git a/zh-CN/src/basic-types/numbers.md b/zh-CN/src/basic-types/numbers.md new file mode 100644 index 0000000..bbdcf5e --- /dev/null +++ b/zh-CN/src/basic-types/numbers.md @@ -0,0 +1 @@ +# Numbers diff --git a/zh-CN/src/basic-types/statements-expressions.md b/zh-CN/src/basic-types/statements-expressions.md new file mode 100644 index 0000000..d1f2555 --- /dev/null +++ b/zh-CN/src/basic-types/statements-expressions.md @@ -0,0 +1 @@ +# Statements and Expressions diff --git a/zh-CN/src/circle-refer b/zh-CN/src/circle-refer new file mode 100644 index 0000000..04b7a8f --- /dev/null +++ b/zh-CN/src/circle-refer @@ -0,0 +1 @@ +# Weak and Circle reference diff --git a/zh-CN/src/circle-reference/intro.md b/zh-CN/src/circle-reference/intro.md new file mode 100644 index 0000000..4f99ca5 --- /dev/null +++ b/zh-CN/src/circle-reference/intro.md @@ -0,0 +1 @@ +# Circle reference and Self referential diff --git a/zh-CN/src/collections/hashmap.md b/zh-CN/src/collections/hashmap.md new file mode 100644 index 0000000..96e549d --- /dev/null +++ b/zh-CN/src/collections/hashmap.md @@ -0,0 +1 @@ +# HashMap diff --git a/zh-CN/src/collections/intro.md b/zh-CN/src/collections/intro.md new file mode 100644 index 0000000..1bdd607 --- /dev/null +++ b/zh-CN/src/collections/intro.md @@ -0,0 +1 @@ +# Collection Types diff --git a/zh-CN/src/collections/vector.md b/zh-CN/src/collections/vector.md new file mode 100644 index 0000000..a2303c1 --- /dev/null +++ b/zh-CN/src/collections/vector.md @@ -0,0 +1 @@ +# Vector diff --git a/zh-CN/src/comments-docs.md b/zh-CN/src/comments-docs.md new file mode 100644 index 0000000..cb7d70d --- /dev/null +++ b/zh-CN/src/comments-docs.md @@ -0,0 +1 @@ +# Comments and Docs diff --git a/zh-CN/src/compound-types/array.md b/zh-CN/src/compound-types/array.md new file mode 100644 index 0000000..92c587c --- /dev/null +++ b/zh-CN/src/compound-types/array.md @@ -0,0 +1 @@ +# array diff --git a/zh-CN/src/compound-types/enum.md b/zh-CN/src/compound-types/enum.md new file mode 100644 index 0000000..298e31d --- /dev/null +++ b/zh-CN/src/compound-types/enum.md @@ -0,0 +1 @@ +# enum diff --git a/zh-CN/src/compound-types/intro.md b/zh-CN/src/compound-types/intro.md new file mode 100644 index 0000000..0c35451 --- /dev/null +++ b/zh-CN/src/compound-types/intro.md @@ -0,0 +1 @@ +# Compound Types diff --git a/zh-CN/src/compound-types/string-slice.md b/zh-CN/src/compound-types/string-slice.md new file mode 100644 index 0000000..9f17363 --- /dev/null +++ b/zh-CN/src/compound-types/string-slice.md @@ -0,0 +1 @@ +# string and slice diff --git a/zh-CN/src/compound-types/struct.md b/zh-CN/src/compound-types/struct.md new file mode 100644 index 0000000..4b9489b --- /dev/null +++ b/zh-CN/src/compound-types/struct.md @@ -0,0 +1 @@ +# struct diff --git a/zh-CN/src/compound-types/tuple.md b/zh-CN/src/compound-types/tuple.md new file mode 100644 index 0000000..ebbc1a7 --- /dev/null +++ b/zh-CN/src/compound-types/tuple.md @@ -0,0 +1 @@ +# tuple diff --git a/zh-CN/src/crate b/zh-CN/src/crate new file mode 100644 index 0000000..e66fb06 --- /dev/null +++ b/zh-CN/src/crate @@ -0,0 +1 @@ +# Crate diff --git a/zh-CN/src/crate-module/crate.md b/zh-CN/src/crate-module/crate.md new file mode 100644 index 0000000..e66fb06 --- /dev/null +++ b/zh-CN/src/crate-module/crate.md @@ -0,0 +1 @@ +# Crate diff --git a/zh-CN/src/crate-module/intro.md b/zh-CN/src/crate-module/intro.md new file mode 100644 index 0000000..dadbf20 --- /dev/null +++ b/zh-CN/src/crate-module/intro.md @@ -0,0 +1 @@ +# Crate and module diff --git a/zh-CN/src/crate-module/module.md b/zh-CN/src/crate-module/module.md new file mode 100644 index 0000000..b785ceb --- /dev/null +++ b/zh-CN/src/crate-module/module.md @@ -0,0 +1 @@ +# Module diff --git a/zh-CN/src/crate-module/use-pub.md b/zh-CN/src/crate-module/use-pub.md new file mode 100644 index 0000000..60c6894 --- /dev/null +++ b/zh-CN/src/crate-module/use-pub.md @@ -0,0 +1 @@ +# use and pub diff --git a/zh-CN/src/errors.md b/zh-CN/src/errors.md new file mode 100644 index 0000000..165d08c --- /dev/null +++ b/zh-CN/src/errors.md @@ -0,0 +1 @@ +# Errors diff --git a/zh-CN/src/flow-control.md b/zh-CN/src/flow-control.md new file mode 100644 index 0000000..cf0c99f --- /dev/null +++ b/zh-CN/src/flow-control.md @@ -0,0 +1 @@ +# Flow Control diff --git a/zh-CN/src/formatted-output.md b/zh-CN/src/formatted-output.md new file mode 100644 index 0000000..5cd8a3b --- /dev/null +++ b/zh-CN/src/formatted-output.md @@ -0,0 +1 @@ +# Formatted output diff --git a/zh-CN/src/functional-programing/cloure.md b/zh-CN/src/functional-programing/cloure.md new file mode 100644 index 0000000..fb73740 --- /dev/null +++ b/zh-CN/src/functional-programing/cloure.md @@ -0,0 +1,51 @@ +# Closure + +下面代码是Rust圣经课程中[闭包](http://course.rs/advance/functional-programing/closure.html#结构体中的闭包)章节的课内练习题答案: + +```rust +struct Cacher +where + T: Fn(E) -> E, + E: Copy +{ + query: T, + value: Option, +} + +impl Cacher +where + T: Fn(E) -> E, + E: Copy +{ + fn new(query: T) -> Cacher { + Cacher { + query, + value: None, + } + } + + fn value(&mut self, arg: E) -> E { + match self.value { + Some(v) => v, + None => { + let v = (self.query)(arg); + self.value = Some(v); + v + } + } + } +} +fn main() { + +} + +#[test] +fn call_with_different_values() { + let mut c = Cacher::new(|a| a); + + let v1 = c.value(1); + let v2 = c.value(2); + + assert_eq!(v2, 1); +} +``` \ No newline at end of file diff --git a/zh-CN/src/functional-programing/intro.md b/zh-CN/src/functional-programing/intro.md new file mode 100644 index 0000000..6f326b8 --- /dev/null +++ b/zh-CN/src/functional-programing/intro.md @@ -0,0 +1 @@ +# Functional programing diff --git a/zh-CN/src/functional-programing/iterator.md b/zh-CN/src/functional-programing/iterator.md new file mode 100644 index 0000000..2a4a2aa --- /dev/null +++ b/zh-CN/src/functional-programing/iterator.md @@ -0,0 +1 @@ +# Iterator diff --git a/zh-CN/src/functional-programming/closure.md b/zh-CN/src/functional-programming/closure.md new file mode 100644 index 0000000..fb73740 --- /dev/null +++ b/zh-CN/src/functional-programming/closure.md @@ -0,0 +1,51 @@ +# Closure + +下面代码是Rust圣经课程中[闭包](http://course.rs/advance/functional-programing/closure.html#结构体中的闭包)章节的课内练习题答案: + +```rust +struct Cacher +where + T: Fn(E) -> E, + E: Copy +{ + query: T, + value: Option, +} + +impl Cacher +where + T: Fn(E) -> E, + E: Copy +{ + fn new(query: T) -> Cacher { + Cacher { + query, + value: None, + } + } + + fn value(&mut self, arg: E) -> E { + match self.value { + Some(v) => v, + None => { + let v = (self.query)(arg); + self.value = Some(v); + v + } + } + } +} +fn main() { + +} + +#[test] +fn call_with_different_values() { + let mut c = Cacher::new(|a| a); + + let v1 = c.value(1); + let v2 = c.value(2); + + assert_eq!(v2, 1); +} +``` \ No newline at end of file diff --git a/zh-CN/src/functional-programming/intro.md b/zh-CN/src/functional-programming/intro.md new file mode 100644 index 0000000..dca041e --- /dev/null +++ b/zh-CN/src/functional-programming/intro.md @@ -0,0 +1 @@ +# Functional Programming diff --git a/zh-CN/src/generics-traits/advance-traits.md b/zh-CN/src/generics-traits/advance-traits.md new file mode 100644 index 0000000..8cd2f63 --- /dev/null +++ b/zh-CN/src/generics-traits/advance-traits.md @@ -0,0 +1 @@ +# Advance Traits diff --git a/zh-CN/src/generics-traits/generics.md b/zh-CN/src/generics-traits/generics.md new file mode 100644 index 0000000..292d26b --- /dev/null +++ b/zh-CN/src/generics-traits/generics.md @@ -0,0 +1 @@ +# Generics diff --git a/zh-CN/src/generics-traits/intro.md b/zh-CN/src/generics-traits/intro.md new file mode 100644 index 0000000..340ad0e --- /dev/null +++ b/zh-CN/src/generics-traits/intro.md @@ -0,0 +1 @@ +# Generics and Traits diff --git a/zh-CN/src/generics-traits/trait-object.md b/zh-CN/src/generics-traits/trait-object.md new file mode 100644 index 0000000..38a0b34 --- /dev/null +++ b/zh-CN/src/generics-traits/trait-object.md @@ -0,0 +1 @@ +# Trait Object diff --git a/zh-CN/src/generics-traits/traits.md b/zh-CN/src/generics-traits/traits.md new file mode 100644 index 0000000..445d444 --- /dev/null +++ b/zh-CN/src/generics-traits/traits.md @@ -0,0 +1 @@ +# Traits diff --git a/zh-CN/src/global-variables.md b/zh-CN/src/global-variables.md new file mode 100644 index 0000000..ad85421 --- /dev/null +++ b/zh-CN/src/global-variables.md @@ -0,0 +1 @@ +# Global variables diff --git a/zh-CN/src/lifetime/advance.md b/zh-CN/src/lifetime/advance.md new file mode 100644 index 0000000..4ee0e07 --- /dev/null +++ b/zh-CN/src/lifetime/advance.md @@ -0,0 +1 @@ +# advance diff --git a/zh-CN/src/lifetime/basic.md b/zh-CN/src/lifetime/basic.md new file mode 100644 index 0000000..40439f4 --- /dev/null +++ b/zh-CN/src/lifetime/basic.md @@ -0,0 +1,26 @@ +## 生命周期消除 + +```rust +fn print(s: &str); // elided +fn print<'a>(s: &'a str); // expanded + +fn debug(lvl: usize, s: &str); // elided +fn debug<'a>(lvl: usize, s: &'a str); // expanded + +fn substr(s: &str, until: usize) -> &str; // elided +fn substr<'a>(s: &'a str, until: usize) -> &'a str; // expanded + +fn get_str() -> &str; // ILLEGAL + +fn frob(s: &str, t: &str) -> &str; // ILLEGAL + +fn get_mut(&mut self) -> &mut T; // elided +fn get_mut<'a>(&'a mut self) -> &'a mut T; // expanded + +fn args(&mut self, args: &[T]) -> &mut Command // elided +fn args<'a, 'b, T: ToCStr>(&'a mut self, args: &'b [T]) -> &'a mut Command // expanded + +fn new(buf: &mut [u8]) -> BufWriter; // elided +fn new(buf: &mut [u8]) -> BufWriter<'_>; // elided (with `rust_2018_idioms`) +fn new<'a>(buf: &'a mut [u8]) -> BufWriter<'a> // expanded +``` \ No newline at end of file diff --git a/zh-CN/src/lifetime/intro.md b/zh-CN/src/lifetime/intro.md new file mode 100644 index 0000000..2615315 --- /dev/null +++ b/zh-CN/src/lifetime/intro.md @@ -0,0 +1 @@ +# Lifetime diff --git a/zh-CN/src/lifetime/static.md b/zh-CN/src/lifetime/static.md new file mode 100644 index 0000000..782446e --- /dev/null +++ b/zh-CN/src/lifetime/static.md @@ -0,0 +1,49 @@ +# &'static and T: 'static + +```rust,editable +use std::fmt::Display; + +fn main() { + let mut string = "First".to_owned(); + + string.push_str(string.to_uppercase().as_str()); + print_a(&string); + print_b(&string); + print_c(&string); // Compilation error + print_d(&string); // Compilation error + print_e(&string); + print_f(&string); + print_g(&string); // Compilation error +} + +fn print_a(t: &T) { + println!("{}", t); +} + +fn print_b(t: &T) +where + T: Display + 'static, +{ + println!("{}", t); +} + +fn print_c(t: &'static dyn Display) { + println!("{}", t) +} + +fn print_d(t: &'static impl Display) { + println!("{}", t) +} + +fn print_e(t: &(dyn Display + 'static)) { + println!("{}", t) +} + +fn print_f(t: &(impl Display + 'static)) { + println!("{}", t) +} + +fn print_g(t: &'static String) { + println!("{}", t); +} +``` \ No newline at end of file diff --git a/zh-CN/src/macro.md b/zh-CN/src/macro.md new file mode 100644 index 0000000..20503ba --- /dev/null +++ b/zh-CN/src/macro.md @@ -0,0 +1 @@ +# macro diff --git a/zh-CN/src/method.md b/zh-CN/src/method.md new file mode 100644 index 0000000..81d5a1c --- /dev/null +++ b/zh-CN/src/method.md @@ -0,0 +1 @@ +# Method diff --git a/zh-CN/src/newtype-sized.md b/zh-CN/src/newtype-sized.md new file mode 100644 index 0000000..fc3f074 --- /dev/null +++ b/zh-CN/src/newtype-sized.md @@ -0,0 +1 @@ +# newtype and Sized diff --git a/zh-CN/src/ownership/borrowing.md b/zh-CN/src/ownership/borrowing.md new file mode 100644 index 0000000..9ce0535 --- /dev/null +++ b/zh-CN/src/ownership/borrowing.md @@ -0,0 +1 @@ +# Reference and Borrowing diff --git a/zh-CN/src/ownership/intro.md b/zh-CN/src/ownership/intro.md new file mode 100644 index 0000000..e749a67 --- /dev/null +++ b/zh-CN/src/ownership/intro.md @@ -0,0 +1 @@ +# Ownership and Borrowing diff --git a/zh-CN/src/ownership/ownership.md b/zh-CN/src/ownership/ownership.md new file mode 100644 index 0000000..77f5a52 --- /dev/null +++ b/zh-CN/src/ownership/ownership.md @@ -0,0 +1 @@ +# Ownership diff --git a/zh-CN/src/pattern-match/intro.md b/zh-CN/src/pattern-match/intro.md new file mode 100644 index 0000000..ee4bb18 --- /dev/null +++ b/zh-CN/src/pattern-match/intro.md @@ -0,0 +1 @@ +# Pattern Match diff --git a/zh-CN/src/pattern-match/match-iflet.md b/zh-CN/src/pattern-match/match-iflet.md new file mode 100644 index 0000000..18eed0e --- /dev/null +++ b/zh-CN/src/pattern-match/match-iflet.md @@ -0,0 +1 @@ +# match, if let diff --git a/zh-CN/src/pattern-match/option.md b/zh-CN/src/pattern-match/option.md new file mode 100644 index 0000000..cb5ffa1 --- /dev/null +++ b/zh-CN/src/pattern-match/option.md @@ -0,0 +1 @@ +# Option destructing diff --git a/zh-CN/src/pattern-match/patterns.md b/zh-CN/src/pattern-match/patterns.md new file mode 100644 index 0000000..3c9daa3 --- /dev/null +++ b/zh-CN/src/pattern-match/patterns.md @@ -0,0 +1 @@ +# Patterns diff --git a/zh-CN/src/resu b/zh-CN/src/resu new file mode 100644 index 0000000..b82dd9a --- /dev/null +++ b/zh-CN/src/resu @@ -0,0 +1 @@ +# panic! diff --git a/zh-CN/src/result-panic/intro.md b/zh-CN/src/result-panic/intro.md new file mode 100644 index 0000000..f724a70 --- /dev/null +++ b/zh-CN/src/result-panic/intro.md @@ -0,0 +1 @@ +# Result and panic diff --git a/zh-CN/src/result-panic/panic.md b/zh-CN/src/result-panic/panic.md new file mode 100644 index 0000000..b82dd9a --- /dev/null +++ b/zh-CN/src/result-panic/panic.md @@ -0,0 +1 @@ +# panic! diff --git a/zh-CN/src/result-panic/result.md b/zh-CN/src/result-panic/result.md new file mode 100644 index 0000000..7af6baf --- /dev/null +++ b/zh-CN/src/result-panic/result.md @@ -0,0 +1 @@ +# result and ? diff --git a/zh-CN/src/self-referential.md b/zh-CN/src/self-referential.md new file mode 100644 index 0000000..37a4784 --- /dev/null +++ b/zh-CN/src/self-referential.md @@ -0,0 +1 @@ +# Self referential diff --git a/zh-CN/src/smart-pointers/box.md b/zh-CN/src/smart-pointers/box.md new file mode 100644 index 0000000..2436f01 --- /dev/null +++ b/zh-CN/src/smart-pointers/box.md @@ -0,0 +1 @@ +# Box diff --git a/zh-CN/src/smart-pointers/cell-refcell.md b/zh-CN/src/smart-pointers/cell-refcell.md new file mode 100644 index 0000000..4e61a02 --- /dev/null +++ b/zh-CN/src/smart-pointers/cell-refcell.md @@ -0,0 +1 @@ +# Cell and RefCell diff --git a/zh-CN/src/smart-pointers/deref.md b/zh-CN/src/smart-pointers/deref.md new file mode 100644 index 0000000..8c709e8 --- /dev/null +++ b/zh-CN/src/smart-pointers/deref.md @@ -0,0 +1 @@ +# Deref diff --git a/zh-CN/src/smart-pointers/drop.md b/zh-CN/src/smart-pointers/drop.md new file mode 100644 index 0000000..c6ecf82 --- /dev/null +++ b/zh-CN/src/smart-pointers/drop.md @@ -0,0 +1 @@ +# Drop diff --git a/zh-CN/src/smart-pointers/intro.md b/zh-CN/src/smart-pointers/intro.md new file mode 100644 index 0000000..997d50c --- /dev/null +++ b/zh-CN/src/smart-pointers/intro.md @@ -0,0 +1 @@ +# Smart pointers diff --git a/zh-CN/src/smart-pointers/rc-arc.md b/zh-CN/src/smart-pointers/rc-arc.md new file mode 100644 index 0000000..8f723ed --- /dev/null +++ b/zh-CN/src/smart-pointers/rc-arc.md @@ -0,0 +1 @@ +# Rc and Arc diff --git a/zh-CN/src/tests/assertions.md b/zh-CN/src/tests/assertions.md new file mode 100644 index 0000000..f5743ab --- /dev/null +++ b/zh-CN/src/tests/assertions.md @@ -0,0 +1 @@ +# Assertions diff --git a/zh-CN/src/tests/benchmark.md b/zh-CN/src/tests/benchmark.md new file mode 100644 index 0000000..f883201 --- /dev/null +++ b/zh-CN/src/tests/benchmark.md @@ -0,0 +1,3 @@ +# Benchmark + +https://doc.rust-lang.org/unstable-book/library-features/test.html \ No newline at end of file diff --git a/zh-CN/src/tests/intro.md b/zh-CN/src/tests/intro.md new file mode 100644 index 0000000..007eb95 --- /dev/null +++ b/zh-CN/src/tests/intro.md @@ -0,0 +1 @@ +# Tests diff --git a/zh-CN/src/tests/unit-integration.md b/zh-CN/src/tests/unit-integration.md new file mode 100644 index 0000000..68df7e4 --- /dev/null +++ b/zh-CN/src/tests/unit-integration.md @@ -0,0 +1 @@ +# Unit and Integration diff --git a/zh-CN/src/tests/write-tests.md b/zh-CN/src/tests/write-tests.md new file mode 100644 index 0000000..245c701 --- /dev/null +++ b/zh-CN/src/tests/write-tests.md @@ -0,0 +1 @@ +# Write Tests diff --git a/zh-CN/src/threads/atomic.md b/zh-CN/src/threads/atomic.md new file mode 100644 index 0000000..eecfaa8 --- /dev/null +++ b/zh-CN/src/threads/atomic.md @@ -0,0 +1 @@ +# Atomic diff --git a/zh-CN/src/threads/basic-using.md b/zh-CN/src/threads/basic-using.md new file mode 100644 index 0000000..f0a2d46 --- /dev/null +++ b/zh-CN/src/threads/basic-using.md @@ -0,0 +1 @@ +# Basic using diff --git a/zh-CN/src/threads/intro.md b/zh-CN/src/threads/intro.md new file mode 100644 index 0000000..f60f399 --- /dev/null +++ b/zh-CN/src/threads/intro.md @@ -0,0 +1 @@ +# Threads diff --git a/zh-CN/src/threads/message-passing.md b/zh-CN/src/threads/message-passing.md new file mode 100644 index 0000000..4d33941 --- /dev/null +++ b/zh-CN/src/threads/message-passing.md @@ -0,0 +1 @@ +# Message passing diff --git a/zh-CN/src/threads/send-sync.md b/zh-CN/src/threads/send-sync.md new file mode 100644 index 0000000..171f95f --- /dev/null +++ b/zh-CN/src/threads/send-sync.md @@ -0,0 +1 @@ +# Send and Sync diff --git a/zh-CN/src/threads/sync.md b/zh-CN/src/threads/sync.md new file mode 100644 index 0000000..bc4491e --- /dev/null +++ b/zh-CN/src/threads/sync.md @@ -0,0 +1 @@ +# Sync diff --git a/zh-CN/src/type-conversion.md b/zh-CN/src/type-conversion.md new file mode 100644 index 0000000..7b930e5 --- /dev/null +++ b/zh-CN/src/type-conversion.md @@ -0,0 +1 @@ +# Type Conversion diff --git a/zh-CN/src/unsafe.md b/zh-CN/src/unsafe.md new file mode 100644 index 0000000..df49df6 --- /dev/null +++ b/zh-CN/src/unsafe.md @@ -0,0 +1 @@ +# unsafe diff --git a/zh-CN/src/variables.md b/zh-CN/src/variables.md new file mode 100644 index 0000000..ee1fba4 --- /dev/null +++ b/zh-CN/src/variables.md @@ -0,0 +1 @@ +# Variables diff --git a/zh-CN/src/weak.md b/zh-CN/src/weak.md new file mode 100644 index 0000000..04b7a8f --- /dev/null +++ b/zh-CN/src/weak.md @@ -0,0 +1 @@ +# Weak and Circle reference diff --git a/zh-CN/src/why-exercise.md b/zh-CN/src/why-exercise.md new file mode 100644 index 0000000..c3e5e3f --- /dev/null +++ b/zh-CN/src/why-exercise.md @@ -0,0 +1 @@ +# Why Exercise.rs