add table of contents for exercise book
This commit is contained in:
parent
f252acdee4
commit
8456088a7b
|
@ -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)
|
||||
|
|
@ -0,0 +1 @@
|
|||
# async and await!
|
|
@ -0,0 +1 @@
|
|||
# Future
|
|
@ -0,0 +1 @@
|
|||
# Async/Await
|
|
@ -0,0 +1 @@
|
|||
# Pin and Unpin
|
|
@ -0,0 +1 @@
|
|||
# Stream
|
|
@ -0,0 +1 @@
|
|||
# Char, Bool and Unit
|
|
@ -0,0 +1 @@
|
|||
# Functions
|
|
@ -0,0 +1 @@
|
|||
# Basic Types
|
|
@ -0,0 +1 @@
|
|||
# Numbers
|
|
@ -0,0 +1 @@
|
|||
# Statements and Expressions
|
|
@ -0,0 +1 @@
|
|||
# Weak and Circle reference
|
|
@ -0,0 +1 @@
|
|||
# Circle reference and Self referential
|
|
@ -0,0 +1 @@
|
|||
# HashMap
|
|
@ -0,0 +1 @@
|
|||
# Collection Types
|
|
@ -0,0 +1 @@
|
|||
# Vector
|
|
@ -0,0 +1 @@
|
|||
# Comments and Docs
|
|
@ -0,0 +1 @@
|
|||
# array
|
|
@ -0,0 +1 @@
|
|||
# enum
|
|
@ -0,0 +1 @@
|
|||
# Compound Types
|
|
@ -0,0 +1 @@
|
|||
# string and slice
|
|
@ -0,0 +1 @@
|
|||
# struct
|
|
@ -0,0 +1 @@
|
|||
# tuple
|
|
@ -0,0 +1 @@
|
|||
# Crate
|
|
@ -0,0 +1 @@
|
|||
# Crate and module
|
|
@ -0,0 +1 @@
|
|||
# Module
|
|
@ -0,0 +1 @@
|
|||
# use and pub
|
|
@ -0,0 +1 @@
|
|||
# Errors
|
|
@ -0,0 +1 @@
|
|||
# Flow Control
|
|
@ -0,0 +1 @@
|
|||
# Formatted output
|
|
@ -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);
|
||||
}
|
||||
```
|
|
@ -0,0 +1 @@
|
|||
# Functional programing
|
|
@ -0,0 +1 @@
|
|||
# Iterator
|
|
@ -0,0 +1 @@
|
|||
# Advance Traits
|
|
@ -0,0 +1 @@
|
|||
# Generics
|
|
@ -0,0 +1 @@
|
|||
# Generics and Traits
|
|
@ -0,0 +1 @@
|
|||
# Trait Object
|
|
@ -0,0 +1 @@
|
|||
# Traits
|
|
@ -0,0 +1 @@
|
|||
# Global variables
|
|
@ -0,0 +1 @@
|
|||
# advance
|
|
@ -0,0 +1 @@
|
|||
# macro
|
|
@ -0,0 +1 @@
|
|||
# Method
|
|
@ -0,0 +1 @@
|
|||
# newtype and Sized
|
|
@ -0,0 +1 @@
|
|||
# Reference and Borrowing
|
|
@ -0,0 +1 @@
|
|||
# Ownership and Borrowing
|
|
@ -0,0 +1 @@
|
|||
# Ownership
|
|
@ -0,0 +1 @@
|
|||
# Pattern Match
|
|
@ -0,0 +1 @@
|
|||
# match, if let
|
|
@ -0,0 +1 @@
|
|||
# Option destructing
|
|
@ -0,0 +1 @@
|
|||
# Patterns
|
|
@ -0,0 +1 @@
|
|||
# Result and panic
|
|
@ -0,0 +1 @@
|
|||
# panic!
|
|
@ -0,0 +1 @@
|
|||
# result and ?
|
|
@ -0,0 +1 @@
|
|||
# Self referential
|
|
@ -0,0 +1 @@
|
|||
# Box
|
|
@ -0,0 +1 @@
|
|||
# Cell and RefCell
|
|
@ -0,0 +1 @@
|
|||
# Deref
|
|
@ -0,0 +1 @@
|
|||
# Drop
|
|
@ -0,0 +1 @@
|
|||
# Smart pointers
|
|
@ -0,0 +1 @@
|
|||
# Rc and Arc
|
|
@ -0,0 +1 @@
|
|||
# Assertions
|
|
@ -0,0 +1 @@
|
|||
# Unit and Integration
|
|
@ -0,0 +1 @@
|
|||
# Write Tests
|
|
@ -0,0 +1 @@
|
|||
# Atomic
|
|
@ -0,0 +1 @@
|
|||
# Basic using
|
|
@ -0,0 +1 @@
|
|||
# Threads
|
|
@ -0,0 +1 @@
|
|||
# Message passing
|
|
@ -0,0 +1 @@
|
|||
# Send and Sync
|
|
@ -0,0 +1 @@
|
|||
# Sync
|
|
@ -0,0 +1 @@
|
|||
# Type Conversion
|
|
@ -0,0 +1 @@
|
|||
# unsafe
|
|
@ -0,0 +1 @@
|
|||
# Variables
|
|
@ -0,0 +1 @@
|
|||
# Weak and Circle reference
|
|
@ -0,0 +1 @@
|
|||
# Why Exercise.rs
|
Loading…
Reference in New Issue