add chapter: fighting with compiler
This commit is contained in:
parent
136d44149b
commit
346fba581b
|
@ -0,0 +1,26 @@
|
|||
1.
|
||||
```rust
|
||||
struct test {
|
||||
list: Vec<i32>,
|
||||
a: i32
|
||||
}
|
||||
|
||||
impl test {
|
||||
pub fn new() -> Self {
|
||||
test { list:vec![1,2,3,4,5,6,7], a:0 }
|
||||
}
|
||||
|
||||
pub fn run(&mut self) {
|
||||
for i in 0..self.list.len() {
|
||||
self.do_something(self.list[i])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn do_something(&mut self, n: i32) {
|
||||
self.a = n;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
```
|
|
@ -39,7 +39,7 @@
|
|||
- [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 and Module](crate-module/intro.md)
|
||||
- [Package and Crate](crate-module/crate.md)
|
||||
- [Module](crate-module/module.md)
|
||||
- [Advanced use and pub](crate-module/use-pub.md)
|
||||
|
@ -84,4 +84,7 @@
|
|||
- [Stream](async/stream.md)
|
||||
|
||||
- [Standard Library TODO](std/intro.md)
|
||||
- [String](std/String.md)
|
||||
- [String](std/String.md)
|
||||
|
||||
- [Fighting with Compiler](fight-compiler/intro.md)
|
||||
- [Borrowing](fight-compiler/borrowing.md)
|
|
@ -0,0 +1,29 @@
|
|||
# Borrowing
|
||||
|
||||
1. 🌟🌟
|
||||
```rust,editable
|
||||
// FIX the error without removing any code line
|
||||
struct test {
|
||||
list: Vec<i32>,
|
||||
a: i32
|
||||
}
|
||||
|
||||
impl test {
|
||||
pub fn new() -> Self {
|
||||
test { list:vec![1,2,3,4,5,6,7], a:0 }
|
||||
}
|
||||
|
||||
pub fn run(&mut self) {
|
||||
for i in self.list.iter() {
|
||||
self.do_something(*i)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn do_something(&mut self, n: i32) {
|
||||
self.a = n;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
```
|
|
@ -0,0 +1,4 @@
|
|||
# Fighting with Compiler
|
||||
Fighting with compiler is very common in our daily coding, especially for those unfamiliar with Rust.
|
||||
|
||||
This chapter will provide some exercises to help us avoid such cases to lower the steep learning curve.
|
|
@ -1,6 +1,6 @@
|
|||
# Summary
|
||||
|
||||
- [关于 pracitce.rs](about.md)
|
||||
- [关于 pracitce.rs](why-exercise.md)
|
||||
- [变量绑定与解构](variables.md)
|
||||
- [基本类型](basic-types/intro.md)
|
||||
- [数值类型](basic-types/numbers.md)
|
||||
|
|
Loading…
Reference in New Issue