fix some typos
Signed-off-by: cui fliter <imcusg@gmail.com>
This commit is contained in:
parent
68ab163a65
commit
2eeb2124ef
|
@ -110,7 +110,7 @@ var initAll = function () {
|
|||
pagePath = "index"
|
||||
}
|
||||
|
||||
// add vistors count
|
||||
// add visitors count
|
||||
var ele = document.createElement("div");
|
||||
ele.setAttribute("align","center");
|
||||
var count = document.createElement("img")
|
||||
|
|
|
@ -53,7 +53,7 @@ fn main() {
|
|||
3. 🌟🌟
|
||||
```rust,editable
|
||||
|
||||
// Question: how many heap allocations are happend here ?
|
||||
// Question: how many heap allocations are happened here ?
|
||||
// Your answer:
|
||||
fn main() {
|
||||
// Create a String type based on `&str`
|
||||
|
|
|
@ -135,7 +135,7 @@ fn main() {
|
|||
}
|
||||
```
|
||||
|
||||
## Capture the enviroments
|
||||
## Capture the environments
|
||||
9.🌟🌟🌟
|
||||
```rust,editable
|
||||
fn get_person() -> String {
|
||||
|
|
|
@ -251,7 +251,7 @@ fn main() {
|
|||
### Iterator adaptors
|
||||
Methods allowing you to change one iterator into another iterator are known as *iterator adaptors*. You can chain multiple iterator adaptors to perform complex actions in a readable way.
|
||||
|
||||
But beacuse **all iterators are lazy**, you have to call one of the consuming adapers to get results from calls to iterator adapters.
|
||||
But because **all iterators are lazy**, you have to call one of the consuming adapers to get results from calls to iterator adapters.
|
||||
|
||||
10、🌟🌟
|
||||
```rust,editable
|
||||
|
|
|
@ -214,7 +214,7 @@ impl<'a> Reader for BufReader<'a> {
|
|||
// 'a is not used in the following methods
|
||||
}
|
||||
|
||||
// can be writting as :
|
||||
// can be writing as :
|
||||
impl Reader for BufReader<'_> {
|
||||
|
||||
}
|
||||
|
|
|
@ -59,11 +59,11 @@ fn main() {
|
|||
```
|
||||
|
||||
## lifetime annotating
|
||||
The **borrow checker uses explicit lifetime annotations** to determine how long a referrence should be valid.
|
||||
The **borrow checker uses explicit lifetime annotations** to determine how long a reference should be valid.
|
||||
|
||||
But for us users, in most cases, there is no need to annotate the lifetime, because there are several elision rules, before learning these rules, we need to know how to annotate lifetime manually.
|
||||
|
||||
#### funtion
|
||||
#### function
|
||||
Ignoring elision rules, lifetimes in function signatures have a few contraints:
|
||||
|
||||
- any reference must have an annotated lifetime
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# &'static and T: 'static
|
||||
`'static` is a reserverd lifetime name, you might have encountered it serveral times:
|
||||
`'static` is a reserved lifetime name, you might have encountered it serveral times:
|
||||
```rust
|
||||
// A reference with 'static lifetime:
|
||||
let s: &'static str = "hello world";
|
||||
|
|
|
@ -26,7 +26,7 @@ fn main() {
|
|||
}
|
||||
```
|
||||
|
||||
2、🌟 Hide the methods of the orginal type
|
||||
2、🌟 Hide the methods of the original type
|
||||
```rust,editable
|
||||
/* Make it workd */
|
||||
struct Meters(u32);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# panic!
|
||||
The simplest error handling mechanism is to use `panic`. It just prints an error message and starts unwinding the stack, finally exit the current thread:
|
||||
|
||||
- if panic occured in `main` thread, then the program will be exited.
|
||||
- if panic occurred in `main` thread, then the program will be exited.
|
||||
- if in spawned thread, then this thread will be terminated, but the program won't
|
||||
|
||||
|
||||
|
@ -16,13 +16,13 @@ fn drink(beverage: &str) {
|
|||
__
|
||||
}
|
||||
|
||||
println!("Excercise Failed if printing out this line!");
|
||||
println!("Exercise Failed if printing out this line!");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
drink(__);
|
||||
|
||||
println!("Excercise Failed if printing out this line!");
|
||||
println!("Exercise Failed if printing out this line!");
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ fn main() {
|
|||
You can find all the examples and exercises of the `Deref` trait [here](https://practice.rs/smart-pointers/deref.html).
|
||||
|
||||
### transmute
|
||||
`std::mem::transmute` is a **unsafe function** can be used to reinterprets the bits of a value of one type as another type. Both of the orginal and the result types must have the same size and neither of them can be invalid.
|
||||
`std::mem::transmute` is a **unsafe function** can be used to reinterprets the bits of a value of one type as another type. Both of the original and the result types must have the same size and neither of them can be invalid.
|
||||
|
||||
`transmute` is semantically equivalent to a bitwise move of one type into another. It copies the bits from the source value into the destination value, then forgets the original, seems equivalent to C's `memcpy` under the hood.
|
||||
|
||||
|
|
|
@ -331,7 +331,7 @@ In some cases, fine control is needed over the way a register name is formatted
|
|||
|
||||
By default the compiler will always choose the name that refers to the full register size (e.g. `rax` on x86-64, `eax` on x86, etc).
|
||||
|
||||
This default can be overriden by using modifiers on the template string operands, just like you would with format strings:
|
||||
This default can be overridden by using modifiers on the template string operands, just like you would with format strings:
|
||||
|
||||
```rust
|
||||
use std::arch::asm;
|
||||
|
|
|
@ -117,7 +117,7 @@ fn main() {
|
|||
}
|
||||
};
|
||||
|
||||
println!("Excercise Failed if printing out this line!");
|
||||
println!("Exercise Failed if printing out this line!");
|
||||
}
|
||||
|
||||
```
|
|
@ -246,7 +246,7 @@ fn main() {
|
|||
|
||||
```rust
|
||||
/* Fill in the blank and fix the errror */
|
||||
// You can aslo use `impl FnOnce(i32) -> i32`
|
||||
// You can also use `impl FnOnce(i32) -> i32`
|
||||
fn create_fn() -> impl Fn(i32) -> i32 {
|
||||
let num = 5;
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ fn main() {
|
|||
|
||||
for bird in birds {
|
||||
bird.quack();
|
||||
// when duck and swan turns into Bird, they all forgot how to fly, only remeber how to quack
|
||||
// when duck and swan turns into Bird, they all forgot how to fly, only remember how to quack
|
||||
// so, the below code will cause an error
|
||||
// bird.fly();
|
||||
}
|
||||
|
|
|
@ -10,13 +10,13 @@ fn drink(beverage: &str) {
|
|||
panic!("drinked, duang.....peng!")
|
||||
}
|
||||
|
||||
println!("Excercise Failed if printing out this line!");
|
||||
println!("Exercise Failed if printing out this line!");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
drink("lemonade");
|
||||
|
||||
println!("Excercise Failed if printing out this line!");
|
||||
println!("Exercise Failed if printing out this line!");
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ var initAll = function () {
|
|||
pagePath = "index"
|
||||
}
|
||||
|
||||
// add vistors count
|
||||
// add visitors count
|
||||
var ele = document.createElement("div");
|
||||
ele.setAttribute("align","center");
|
||||
var count = document.createElement("img")
|
||||
|
|
|
@ -16,13 +16,13 @@ fn drink(beverage: &str) {
|
|||
__
|
||||
}
|
||||
|
||||
println!("Excercise Failed if printing out this line!");
|
||||
println!("Exercise Failed if printing out this line!");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
drink(__);
|
||||
|
||||
println!("Excercise Failed if printing out this line!");
|
||||
println!("Exercise Failed if printing out this line!");
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -331,7 +331,7 @@ In some cases, fine control is needed over the way a register name is formatted
|
|||
|
||||
By default the compiler will always choose the name that refers to the full register size (e.g. `rax` on x86-64, `eax` on x86, etc).
|
||||
|
||||
This default can be overriden by using modifiers on the template string operands, just like you would with format strings:
|
||||
This default can be overridden by using modifiers on the template string operands, just like you would with format strings:
|
||||
|
||||
```rust
|
||||
use std::arch::asm;
|
||||
|
|
Loading…
Reference in New Issue