mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-08-11 05:54:45 +00:00
add table of contents for exercise book
This commit is contained in:
@@ -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)
|
||||
- [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)
|
||||
|
||||
- [Functional Programming](functional-programming/intro.md)
|
||||
- [Closure](functional-programming/closure.md)
|
1
src/async/async-await.md
Normal file
1
src/async/async-await.md
Normal file
@@ -0,0 +1 @@
|
||||
# async and await!
|
1
src/async/future.md
Normal file
1
src/async/future.md
Normal file
@@ -0,0 +1 @@
|
||||
# Future
|
1
src/async/intro.md
Normal file
1
src/async/intro.md
Normal file
@@ -0,0 +1 @@
|
||||
# Async/Await
|
1
src/async/pin-unpin.md
Normal file
1
src/async/pin-unpin.md
Normal file
@@ -0,0 +1 @@
|
||||
# Pin and Unpin
|
1
src/async/stream.md
Normal file
1
src/async/stream.md
Normal file
@@ -0,0 +1 @@
|
||||
# Stream
|
1
src/basic-types/char-bool-unit.md
Normal file
1
src/basic-types/char-bool-unit.md
Normal file
@@ -0,0 +1 @@
|
||||
# Char, Bool and Unit
|
1
src/basic-types/functions.md
Normal file
1
src/basic-types/functions.md
Normal file
@@ -0,0 +1 @@
|
||||
# Functions
|
1
src/basic-types/intro.md
Normal file
1
src/basic-types/intro.md
Normal file
@@ -0,0 +1 @@
|
||||
# Basic Types
|
1
src/basic-types/numbers.md
Normal file
1
src/basic-types/numbers.md
Normal file
@@ -0,0 +1 @@
|
||||
# Numbers
|
1
src/basic-types/statements-expressions.md
Normal file
1
src/basic-types/statements-expressions.md
Normal file
@@ -0,0 +1 @@
|
||||
# Statements and Expressions
|
1
src/circle-refer
Normal file
1
src/circle-refer
Normal file
@@ -0,0 +1 @@
|
||||
# Weak and Circle reference
|
1
src/circle-reference/intro.md
Normal file
1
src/circle-reference/intro.md
Normal file
@@ -0,0 +1 @@
|
||||
# Circle reference and Self referential
|
1
src/collections/hashmap.md
Normal file
1
src/collections/hashmap.md
Normal file
@@ -0,0 +1 @@
|
||||
# HashMap
|
1
src/collections/intro.md
Normal file
1
src/collections/intro.md
Normal file
@@ -0,0 +1 @@
|
||||
# Collection Types
|
1
src/collections/vector.md
Normal file
1
src/collections/vector.md
Normal file
@@ -0,0 +1 @@
|
||||
# Vector
|
1
src/comments-docs.md
Normal file
1
src/comments-docs.md
Normal file
@@ -0,0 +1 @@
|
||||
# Comments and Docs
|
1
src/compound-types/array.md
Normal file
1
src/compound-types/array.md
Normal file
@@ -0,0 +1 @@
|
||||
# array
|
1
src/compound-types/enum.md
Normal file
1
src/compound-types/enum.md
Normal file
@@ -0,0 +1 @@
|
||||
# enum
|
1
src/compound-types/intro.md
Normal file
1
src/compound-types/intro.md
Normal file
@@ -0,0 +1 @@
|
||||
# Compound Types
|
1
src/compound-types/string-slice.md
Normal file
1
src/compound-types/string-slice.md
Normal file
@@ -0,0 +1 @@
|
||||
# string and slice
|
1
src/compound-types/struct.md
Normal file
1
src/compound-types/struct.md
Normal file
@@ -0,0 +1 @@
|
||||
# struct
|
1
src/compound-types/tuple.md
Normal file
1
src/compound-types/tuple.md
Normal file
@@ -0,0 +1 @@
|
||||
# tuple
|
1
src/crate-module/crate.md
Normal file
1
src/crate-module/crate.md
Normal file
@@ -0,0 +1 @@
|
||||
# Crate
|
1
src/crate-module/intro.md
Normal file
1
src/crate-module/intro.md
Normal file
@@ -0,0 +1 @@
|
||||
# Crate and module
|
1
src/crate-module/module.md
Normal file
1
src/crate-module/module.md
Normal file
@@ -0,0 +1 @@
|
||||
# Module
|
1
src/crate-module/use-pub.md
Normal file
1
src/crate-module/use-pub.md
Normal file
@@ -0,0 +1 @@
|
||||
# use and pub
|
1
src/errors.md
Normal file
1
src/errors.md
Normal file
@@ -0,0 +1 @@
|
||||
# Errors
|
1
src/flow-control.md
Normal file
1
src/flow-control.md
Normal file
@@ -0,0 +1 @@
|
||||
# Flow Control
|
1
src/formatted-output.md
Normal file
1
src/formatted-output.md
Normal file
@@ -0,0 +1 @@
|
||||
# Formatted output
|
51
src/functional-programing/cloure.md
Normal file
51
src/functional-programing/cloure.md
Normal 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);
|
||||
}
|
||||
```
|
1
src/functional-programing/intro.md
Normal file
1
src/functional-programing/intro.md
Normal file
@@ -0,0 +1 @@
|
||||
# Functional programing
|
1
src/functional-programing/iterator.md
Normal file
1
src/functional-programing/iterator.md
Normal file
@@ -0,0 +1 @@
|
||||
# Iterator
|
1
src/generics-traits/advance-traits.md
Normal file
1
src/generics-traits/advance-traits.md
Normal file
@@ -0,0 +1 @@
|
||||
# Advance Traits
|
1
src/generics-traits/generics.md
Normal file
1
src/generics-traits/generics.md
Normal file
@@ -0,0 +1 @@
|
||||
# Generics
|
1
src/generics-traits/intro.md
Normal file
1
src/generics-traits/intro.md
Normal file
@@ -0,0 +1 @@
|
||||
# Generics and Traits
|
1
src/generics-traits/trait-object.md
Normal file
1
src/generics-traits/trait-object.md
Normal file
@@ -0,0 +1 @@
|
||||
# Trait Object
|
1
src/generics-traits/traits.md
Normal file
1
src/generics-traits/traits.md
Normal file
@@ -0,0 +1 @@
|
||||
# Traits
|
1
src/global-variables.md
Normal file
1
src/global-variables.md
Normal file
@@ -0,0 +1 @@
|
||||
# Global variables
|
1
src/lifetime/advance.md
Normal file
1
src/lifetime/advance.md
Normal file
@@ -0,0 +1 @@
|
||||
# advance
|
1
src/macro.md
Normal file
1
src/macro.md
Normal file
@@ -0,0 +1 @@
|
||||
# macro
|
1
src/method.md
Normal file
1
src/method.md
Normal file
@@ -0,0 +1 @@
|
||||
# Method
|
1
src/newtype-sized.md
Normal file
1
src/newtype-sized.md
Normal file
@@ -0,0 +1 @@
|
||||
# newtype and Sized
|
1
src/ownership/borrowing.md
Normal file
1
src/ownership/borrowing.md
Normal file
@@ -0,0 +1 @@
|
||||
# Reference and Borrowing
|
1
src/ownership/intro.md
Normal file
1
src/ownership/intro.md
Normal file
@@ -0,0 +1 @@
|
||||
# Ownership and Borrowing
|
1
src/ownership/ownership.md
Normal file
1
src/ownership/ownership.md
Normal file
@@ -0,0 +1 @@
|
||||
# Ownership
|
1
src/pattern-match/intro.md
Normal file
1
src/pattern-match/intro.md
Normal file
@@ -0,0 +1 @@
|
||||
# Pattern Match
|
1
src/pattern-match/match-iflet.md
Normal file
1
src/pattern-match/match-iflet.md
Normal file
@@ -0,0 +1 @@
|
||||
# match, if let
|
1
src/pattern-match/option.md
Normal file
1
src/pattern-match/option.md
Normal file
@@ -0,0 +1 @@
|
||||
# Option destructing
|
1
src/pattern-match/patterns.md
Normal file
1
src/pattern-match/patterns.md
Normal file
@@ -0,0 +1 @@
|
||||
# Patterns
|
1
src/result-panic/intro.md
Normal file
1
src/result-panic/intro.md
Normal file
@@ -0,0 +1 @@
|
||||
# Result and panic
|
1
src/result-panic/panic.md
Normal file
1
src/result-panic/panic.md
Normal file
@@ -0,0 +1 @@
|
||||
# panic!
|
1
src/result-panic/result.md
Normal file
1
src/result-panic/result.md
Normal file
@@ -0,0 +1 @@
|
||||
# result and ?
|
1
src/self-referential.md
Normal file
1
src/self-referential.md
Normal file
@@ -0,0 +1 @@
|
||||
# Self referential
|
1
src/smart-pointers/box.md
Normal file
1
src/smart-pointers/box.md
Normal file
@@ -0,0 +1 @@
|
||||
# Box
|
1
src/smart-pointers/cell-refcell.md
Normal file
1
src/smart-pointers/cell-refcell.md
Normal file
@@ -0,0 +1 @@
|
||||
# Cell and RefCell
|
1
src/smart-pointers/deref.md
Normal file
1
src/smart-pointers/deref.md
Normal file
@@ -0,0 +1 @@
|
||||
# Deref
|
1
src/smart-pointers/drop.md
Normal file
1
src/smart-pointers/drop.md
Normal file
@@ -0,0 +1 @@
|
||||
# Drop
|
1
src/smart-pointers/intro.md
Normal file
1
src/smart-pointers/intro.md
Normal file
@@ -0,0 +1 @@
|
||||
# Smart pointers
|
1
src/smart-pointers/rc-arc.md
Normal file
1
src/smart-pointers/rc-arc.md
Normal file
@@ -0,0 +1 @@
|
||||
# Rc and Arc
|
1
src/tests/assertions.md
Normal file
1
src/tests/assertions.md
Normal file
@@ -0,0 +1 @@
|
||||
# Assertions
|
1
src/tests/unit-integration.md
Normal file
1
src/tests/unit-integration.md
Normal file
@@ -0,0 +1 @@
|
||||
# Unit and Integration
|
1
src/tests/write-tests.md
Normal file
1
src/tests/write-tests.md
Normal file
@@ -0,0 +1 @@
|
||||
# Write Tests
|
1
src/threads/atomic.md
Normal file
1
src/threads/atomic.md
Normal file
@@ -0,0 +1 @@
|
||||
# Atomic
|
1
src/threads/basic-using.md
Normal file
1
src/threads/basic-using.md
Normal file
@@ -0,0 +1 @@
|
||||
# Basic using
|
1
src/threads/intro.md
Normal file
1
src/threads/intro.md
Normal file
@@ -0,0 +1 @@
|
||||
# Threads
|
1
src/threads/message-passing.md
Normal file
1
src/threads/message-passing.md
Normal file
@@ -0,0 +1 @@
|
||||
# Message passing
|
1
src/threads/send-sync.md
Normal file
1
src/threads/send-sync.md
Normal file
@@ -0,0 +1 @@
|
||||
# Send and Sync
|
1
src/threads/sync.md
Normal file
1
src/threads/sync.md
Normal file
@@ -0,0 +1 @@
|
||||
# Sync
|
1
src/type-conversion.md
Normal file
1
src/type-conversion.md
Normal file
@@ -0,0 +1 @@
|
||||
# Type Conversion
|
1
src/unsafe.md
Normal file
1
src/unsafe.md
Normal file
@@ -0,0 +1 @@
|
||||
# unsafe
|
1
src/variables.md
Normal file
1
src/variables.md
Normal file
@@ -0,0 +1 @@
|
||||
# Variables
|
1
src/weak.md
Normal file
1
src/weak.md
Normal file
@@ -0,0 +1 @@
|
||||
# Weak and Circle reference
|
1
src/why-exercise.md
Normal file
1
src/why-exercise.md
Normal file
@@ -0,0 +1 @@
|
||||
# Why Exercise.rs
|
Reference in New Issue
Block a user