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> {

View File

@ -1,4 +1,5 @@
1、
```rust
fn main() {
let arr = [0; 10];
@ -9,6 +10,7 @@ fn main() {
```
2、
```rust
fn main() {
let mut v = Vec::new();
@ -21,6 +23,7 @@ fn main() {
```
3、
```rust
fn main() {
let v1 = vec![1, 2];
@ -48,6 +51,7 @@ fn main() {
```
4、
```rust
fn main() {
let arr = vec![0; 10];
@ -60,6 +64,7 @@ fn main() {
```
5、
```rust
fn main() {
let mut names = vec!["Bob", "Frank", "Ferris"];
@ -76,6 +81,7 @@ fn main() {
```
6、
```rust
fn main() {
let mut values = vec![1, 2, 3];
@ -90,6 +96,7 @@ fn main() {
```
7、
```rust
struct Fibonacci {
curr: u32,
@ -136,6 +143,7 @@ fn main() {
```
8、
```rust
fn main() {
let v1 = vec![1, 2, 3];
@ -152,6 +160,7 @@ fn main() {
```
9、
```rust
use std::collections::HashMap;
fn main() {
@ -169,6 +178,7 @@ fn main() {
```
10、
```rust
fn main() {
let v1: Vec<i32> = vec![1, 2, 3];
@ -180,6 +190,7 @@ fn main() {
```
11、
```rust
use std::collections::HashMap;
fn main() {
@ -192,6 +203,7 @@ fn main() {
```
12、
```rust
#[derive(PartialEq, Debug)]
struct Shoe {