format code in md

This commit is contained in:
likzn
2022-05-01 13:08:50 +08:00
parent dad4052485
commit e09080f88a
43 changed files with 405 additions and 124 deletions

View File

@@ -1,4 +1,5 @@
1、
```rust
fn main() {
let color = String::from("green");
@@ -13,6 +14,7 @@ fn main() {
```
2、
```rust
fn main() {
let mut count = 0;
@@ -38,6 +40,7 @@ fn main() {
```
3、
```rust
fn main() {
// A non-copy type.
@@ -83,6 +86,7 @@ fn take<T>(_v: &T) {
```
4、
```rust
fn main() {
let example_closure = |x| x;
@@ -95,6 +99,7 @@ fn main() {
```
5、
```rust
fn fn_once<F>(func: F)
where
@@ -126,6 +131,7 @@ fn main() {
```
6、
```rust
fn main() {
let mut s = String::new();
@@ -143,6 +149,7 @@ fn exec<'a, F: FnMut(&'a str)>(mut f: F) {
```
7、
```rust
// A function which takes a closure as an argument and calls it.
// <F> denotes that F is a "Generic type parameter"
@@ -197,6 +204,7 @@ fn main() {
```
8、
```rust
fn main() {
let mut s = String::new();
@@ -212,6 +220,7 @@ fn exec<'a, F: FnOnce(&'a str) -> String>(mut f: F) {
```
9、
```rust
// Define a function which takes a generic `F` argument
// bounded by `Fn`, and calls it
@@ -234,6 +243,7 @@ fn main() {
```
10、
```rust
/* Fill in the blank and fix the errror */
// You can aslo use `impl FnOnce(i32) -> i32`
@@ -268,6 +278,7 @@ fn main() {
```
11、
```rust
// Every closure has its own type. Even if one closure has the same representation as another, their types are different.
fn factory(x:i32) -> Box<dyn Fn(i32) -> i32> {