add table of contents for exercise book

This commit is contained in:
sunface 2022-02-23 14:49:02 +08:00
parent f252acdee4
commit 8456088a7b
76 changed files with 197 additions and 4 deletions

View File

@ -1,11 +1,79 @@
# Summary
- [Why Exercise.rs](why-exercise.md)
- [Variables](variables.md)
- [Basic Types](basic-types/intro.md)
- [Numbers](basic-types/numbers.md)
- [Char, Bool and Unit](basic-types/char-bool-unit.md)
- [Statements and Expressions](basic-types/statements-expressions.md)
- [Functions](basic-types/functions.md)
- [Ownership and Borrowing](ownership/intro.md)
- [Ownership](ownership/ownership.md)
- [Reference and Borrowing](ownership/borrowing.md)
- [Compound Types](compound-types/intro.md)
- [string and slice](compound-types/string-slice.md)
- [tuple](compound-types/tuple.md)
- [struct](compound-types/struct.md)
- [enum](compound-types/enum.md)
- [array](compound-types/array.md)
- [Flow Control](flow-control.md)
- [Pattern Match](pattern-match/intro.md)
- [match, if let](pattern-match/match-iflet.md)
- [Option destructing](pattern-match/option.md)
- [Patterns](pattern-match/patterns.md)
- [Method](method.md)
- [Generics and Traits](generics-traits/intro.md)
- [Generics](generics-traits/generics.md)
- [Traits](generics-traits/traits.md)
- [Trait Object](generics-traits/trait-object.md)
- [Advance Traits](generics-traits/advance-traits.md)
- [Collection Types](collections/intro.md)
- [Vector](collections/vector.md)
- [HashMap](collections/hashmap.md)
- [Type Conversion](type-conversion.md)
- [Result and panic](result-panic/intro.md)
- [panic!](result-panic/panic.md)
- [result and ?](result-panic/result.md)
- [Crate and module](crate-module/intro.md)
- [Crate](crate-module/crate.md)
- [Module](crate-module/module.md)
- [use and pub](crate-module/use-pub.md)
- [Comments and Docs](comments-docs.md)
- [Formatted output](formatted-output.md)
- [Lifetime](lifetime/intro.md)
- [basic](lifetime/basic.md)
- [&'static and T: 'static](lifetime/static.md)
- [advance](lifetime/advance.md)
- [Functional programing](functional-programing/intro.md)
- [Closure](functional-programing/cloure.md)
- [Iterator](functional-programing/iterator.md)
- [newtype and Sized](newtype-sized.md)
- [Smart pointers](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 and Circle reference](weak.md)
- [Self referential](self-referential.md)
- [Threads](threads/intro.md)
- [Basic using](threads/basic-using.md)
- [Message passing](threads/message-passing.md)
- [Sync](threads/sync.md)
- [Atomic](threads/atomic.md)
- [Send and Sync](threads/send-sync.md)
- [Global variables](global-variables.md)
- [Errors](errors.md)
- [unsafe](unsafe.md)
- [macro](macro.md)
- [Tests](tests/intro.md)
- [Write Tests](tests/write-tests.md)
- [Benchmark](tests/benchmark.md)
- [Functional Programming](functional-programming/intro.md)
- [Closure](functional-programming/closure.md)
- [Unit and Integration](tests/unit-integration.md)
- [Assertions](tests/assertions.md)
- [Async/Await](async/intro.md)
- [async and await!](async/async-await.md)
- [Future](async/future.md)
- [Pin and Unpin](async/pin-unpin.md)
- [Stream](async/stream.md)

1
src/async/async-await.md Normal file
View File

@ -0,0 +1 @@
# async and await!

1
src/async/future.md Normal file
View File

@ -0,0 +1 @@
# Future

1
src/async/intro.md Normal file
View File

@ -0,0 +1 @@
# Async/Await

1
src/async/pin-unpin.md Normal file
View File

@ -0,0 +1 @@
# Pin and Unpin

1
src/async/stream.md Normal file
View File

@ -0,0 +1 @@
# Stream

View File

@ -0,0 +1 @@
# Char, Bool and Unit

View File

@ -0,0 +1 @@
# Functions

1
src/basic-types/intro.md Normal file
View File

@ -0,0 +1 @@
# Basic Types

View File

@ -0,0 +1 @@
# Numbers

View File

@ -0,0 +1 @@
# Statements and Expressions

1
src/circle-refer Normal file
View File

@ -0,0 +1 @@
# Weak and Circle reference

View File

@ -0,0 +1 @@
# Circle reference and Self referential

View File

@ -0,0 +1 @@
# HashMap

1
src/collections/intro.md Normal file
View File

@ -0,0 +1 @@
# Collection Types

View File

@ -0,0 +1 @@
# Vector

1
src/comments-docs.md Normal file
View File

@ -0,0 +1 @@
# Comments and Docs

View File

@ -0,0 +1 @@
# array

View File

@ -0,0 +1 @@
# enum

View File

@ -0,0 +1 @@
# Compound Types

View File

@ -0,0 +1 @@
# string and slice

View File

@ -0,0 +1 @@
# struct

View File

@ -0,0 +1 @@
# tuple

1
src/crate Normal file
View File

@ -0,0 +1 @@
# Crate

View File

@ -0,0 +1 @@
# Crate

View File

@ -0,0 +1 @@
# Crate and module

View File

@ -0,0 +1 @@
# Module

View File

@ -0,0 +1 @@
# use and pub

1
src/errors.md Normal file
View File

@ -0,0 +1 @@
# Errors

1
src/flow-control.md Normal file
View File

@ -0,0 +1 @@
# Flow Control

1
src/formatted-output.md Normal file
View File

@ -0,0 +1 @@
# Formatted output

View File

@ -0,0 +1,51 @@
# Closure
下面代码是Rust圣经课程中[闭包](http://course.rs/advance/functional-programing/closure.html#结构体中的闭包)章节的课内练习题答案:
```rust
struct Cacher<T,E>
where
T: Fn(E) -> E,
E: Copy
{
query: T,
value: Option<E>,
}
impl<T,E> Cacher<T,E>
where
T: Fn(E) -> E,
E: Copy
{
fn new(query: T) -> Cacher<T,E> {
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);
}
```

View File

@ -0,0 +1 @@
# Functional programing

View File

@ -0,0 +1 @@
# Iterator

View File

@ -0,0 +1 @@
# Advance Traits

View File

@ -0,0 +1 @@
# Generics

View File

@ -0,0 +1 @@
# Generics and Traits

View File

@ -0,0 +1 @@
# Trait Object

View File

@ -0,0 +1 @@
# Traits

1
src/global-variables.md Normal file
View File

@ -0,0 +1 @@
# Global variables

1
src/lifetime/advance.md Normal file
View File

@ -0,0 +1 @@
# advance

1
src/macro.md Normal file
View File

@ -0,0 +1 @@
# macro

1
src/method.md Normal file
View File

@ -0,0 +1 @@
# Method

1
src/newtype-sized.md Normal file
View File

@ -0,0 +1 @@
# newtype and Sized

View File

@ -0,0 +1 @@
# Reference and Borrowing

1
src/ownership/intro.md Normal file
View File

@ -0,0 +1 @@
# Ownership and Borrowing

View File

@ -0,0 +1 @@
# Ownership

View File

@ -0,0 +1 @@
# Pattern Match

View File

@ -0,0 +1 @@
# match, if let

View File

@ -0,0 +1 @@
# Option destructing

View File

@ -0,0 +1 @@
# Patterns

1
src/resu Normal file
View File

@ -0,0 +1 @@
# panic!

View File

@ -0,0 +1 @@
# Result and panic

View File

@ -0,0 +1 @@
# panic!

View File

@ -0,0 +1 @@
# result and ?

1
src/self-referential.md Normal file
View File

@ -0,0 +1 @@
# Self referential

View File

@ -0,0 +1 @@
# Box

View File

@ -0,0 +1 @@
# Cell and RefCell

View File

@ -0,0 +1 @@
# Deref

View File

@ -0,0 +1 @@
# Drop

View File

@ -0,0 +1 @@
# Smart pointers

View File

@ -0,0 +1 @@
# Rc and Arc

1
src/tests/assertions.md Normal file
View File

@ -0,0 +1 @@
# Assertions

View File

@ -0,0 +1 @@
# Unit and Integration

1
src/tests/write-tests.md Normal file
View File

@ -0,0 +1 @@
# Write Tests

1
src/threads/atomic.md Normal file
View File

@ -0,0 +1 @@
# Atomic

View File

@ -0,0 +1 @@
# Basic using

1
src/threads/intro.md Normal file
View File

@ -0,0 +1 @@
# Threads

View File

@ -0,0 +1 @@
# Message passing

1
src/threads/send-sync.md Normal file
View File

@ -0,0 +1 @@
# Send and Sync

1
src/threads/sync.md Normal file
View File

@ -0,0 +1 @@
# Sync

1
src/type-conversion.md Normal file
View File

@ -0,0 +1 @@
# Type Conversion

1
src/unsafe.md Normal file
View File

@ -0,0 +1 @@
# unsafe

1
src/variables.md Normal file
View File

@ -0,0 +1 @@
# Variables

1
src/weak.md Normal file
View File

@ -0,0 +1 @@
# Weak and Circle reference

1
src/why-exercise.md Normal file
View File

@ -0,0 +1 @@
# Why Exercise.rs