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 arr = [1, 2, 3];
@ -9,18 +10,20 @@ fn main() {
```
2.
```rust
fn main() {
let arr: [char; 3] = ['中', '国', '人'];
let slice = &arr[..2];
// TIPS: slice( reference ) IS NOT an array, if it is an array, then `assert!` will passed: each of the two UTF-8 chars '中' and '国' occupies 3 bytes, 2 * 3 = 6
assert!(std::mem::size_of_val(&slice) == 16);
}
```
3.
```rust
fn main() {
let arr: [i32; 5] = [1, 2, 3, 4, 5];
@ -30,6 +33,7 @@ fn main() {
```
4.
```rust
fn main() {
let s = String::from("hello");
@ -42,6 +46,7 @@ fn main() {
```
5.
```rust
fn main() {
let s = "你好,世界";
@ -52,6 +57,7 @@ fn main() {
```
6.
```rust
fn main() {
let mut s = String::from("hello world");
@ -63,8 +69,8 @@ fn main() {
println!("the first word is: {}", word);
s.clear();
}
fn first_word(s: &str) -> &str {
&s[..1]
}