mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-06-25 05:29:41 +00:00
add chapter: fighting with compiler
This commit is contained in:
@ -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)
|
29
src/fight-compiler/borrowing.md
Normal file
29
src/fight-compiler/borrowing.md
Normal file
@ -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() {}
|
||||
```
|
4
src/fight-compiler/intro.md
Normal file
4
src/fight-compiler/intro.md
Normal file
@ -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.
|
Reference in New Issue
Block a user