Merge pull request #167 from 2432001677/master

fix: ugly identation in compound-types
This commit is contained in:
Sunface 2022-03-25 16:02:23 +08:00 committed by GitHub
commit 20e29eb595
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 65 additions and 65 deletions

View File

@ -37,12 +37,12 @@ fn main() {
```rust,editable
fn main() {
let arr: [i32; 5] = [1, 2, 3, 4, 5];
// fill the blanks to make the code work
let slice: __ = __;
assert_eq!(slice, &[2, 3, 4]);
let arr: [i32; 5] = [1, 2, 3, 4, 5];
// fill the blanks to make the code work
let slice: __ = __;
assert_eq!(slice, &[2, 3, 4]);
println!("Success!")
println!("Success!")
}
```

View File

@ -9,9 +9,9 @@ The type of string literal `"hello, world"` is `&str`, e.g `let s: &str = "hello
// fix error without adding new line
fn main() {
let s: str = "hello, world";
let s: str = "hello, world";
println!("Success!")
println!("Success!")
}
```
@ -22,8 +22,8 @@ fn main() {
// fix the error with at least two solutions
fn main() {
let s: Box<str> = "hello, world".into();
greetings(s)
let s: Box<str> = "hello, world".into();
greetings(s)
}
fn greetings(s: &str) {
@ -39,13 +39,13 @@ fn greetings(s: &str) {
// fill the blank
fn main() {
let mut s = __;
s.push_str("hello, world");
s.push('!');
let mut s = __;
s.push_str("hello, world");
s.push('!');
assert_eq!(s, "hello, world!");
assert_eq!(s, "hello, world!");
println!("Success!")
println!("Success!")
}
```
@ -54,7 +54,7 @@ fn main() {
// fix all errors without adding newline
fn main() {
let s = String::from("hello");
let s = String::from("hello");
s.push(',');
s.push(" world");
s += "!".to_string();
@ -68,13 +68,13 @@ fn main() {
// fill the blank
fn main() {
let s = String::from("I like dogs");
// Allocate new memory and store the modified string there
let s1 = s.__("dogs", "cats");
let s = String::from("I like dogs");
// Allocate new memory and store the modified string there
let s1 = s.__("dogs", "cats");
assert_eq!(s1, "I like cats");
assert_eq!(s1, "I like cats");
println!("Success!")
println!("Success!")
}
```
@ -102,25 +102,25 @@ Opsite to the seldom using of `str`, `&str` and `String` are used everywhere!
// fix error with at lest two solutions
fn main() {
let s = "hello, world";
greetings(s)
let s = "hello, world";
greetings(s)
}
fn greetings(s: String) {
println!("{}",s)
}
```
8. 🌟🌟 We can use `String::from` or `to_string` to convert a `&str` to `String`
```rust,editable
// use two approaches to fix the error and without adding a new line
fn main() {
let s = "hello, world".to_string();
let s1: &str = s;
let s = "hello, world".to_string();
let s1: &str = s;
println!("Success!")
println!("Success!")
}
```
@ -256,10 +256,10 @@ You can use [utf8_slice](https://docs.rs/utf8_slice/1.0.0/utf8_slice/fn.slice.ht
```rust
use utf8_slice;
fn main() {
let s = "The 🚀 goes to the 🌑!";
let s = "The 🚀 goes to the 🌑!";
let rocket = utf8_slice::slice(s, 4, 5);
// Will equal "🚀"
let rocket = utf8_slice::slice(s, 4, 5);
// Will equal "🚀"
}
```

View File

@ -18,10 +18,10 @@ fn main() {
// make it works
fn main() {
let t = ("i", "am", "sunface");
assert_eq!(t.1, "sunface");
let t = ("i", "am", "sunface");
assert_eq!(t.1, "sunface");
println!("Success!")
println!("Success!")
}
```
@ -72,13 +72,13 @@ fn main() {
```rust,editable
fn main() {
// fill the blank, need a few computations here.
let (x, y) = sum_multiply(__);
// fill the blank, need a few computations here.
let (x, y) = sum_multiply(__);
assert_eq!(x, 5);
assert_eq!(y, 6);
assert_eq!(x, 5);
assert_eq!(y, 6);
println!("Success!")
println!("Success!")
}
fn sum_multiply(nums: (i32, i32)) -> (i32, i32) {

View File

@ -35,7 +35,7 @@ fn main() {
```rust,editable
fn main() {
let arr: [i32; 5] = [1, 2, 3, 4, 5];
let arr: [i32; 5] = [1, 2, 3, 4, 5];
// 填空让代码工作起来
let slice: __ = __;
assert_eq!(slice, &[2, 3, 4]);

View File

@ -9,7 +9,7 @@
// 修复错误,不要新增代码行
fn main() {
let s: str = "hello, world";
let s: str = "hello, world";
}
```
@ -20,8 +20,8 @@ fn main() {
// 使用至少两种方法来修复错误
fn main() {
let s: Box<str> = "hello, world".into();
greetings(s)
let s: Box<str> = "hello, world".into();
greetings(s)
}
fn greetings(s: &str) {
@ -37,11 +37,11 @@ fn greetings(s: &str) {
// 填空
fn main() {
let mut s = __;
s.push_str("hello, world");
s.push('!');
let mut s = __;
s.push_str("hello, world");
s.push('!');
assert_eq!(s, "hello, world!");
assert_eq!(s, "hello, world!");
}
```
@ -50,7 +50,7 @@ fn main() {
// 修复所有错误,并且不要新增代码行
fn main() {
let s = String::from("hello");
let s = String::from("hello");
s.push(',');
s.push(" world");
s += "!".to_string();
@ -64,11 +64,11 @@ fn main() {
// 填空
fn main() {
let s = String::from("I like dogs");
// 以下方法会重新分配一块内存空间,然后将修改后的字符串存在这里
let s1 = s.__("dogs", "cats");
let s = String::from("I like dogs");
// 以下方法会重新分配一块内存空间,然后将修改后的字符串存在这里
let s1 = s.__("dogs", "cats");
assert_eq!(s1, "I like cats")
assert_eq!(s1, "I like cats")
}
```
@ -98,23 +98,23 @@ fn main() {
// 使用至少两种方法来修复错误
fn main() {
let s = "hello, world";
greetings(s)
let s = "hello, world";
greetings(s)
}
fn greetings(s: String) {
println!("{}",s)
}
```
8. 🌟🌟 我们可以使用 `String::from``to_string``&str` 转换成 `String` 类型
```rust,editable
// 使用两种方法来解决错误,不要新增代码行
fn main() {
let s = "hello, world".to_string();
let s1: &str = s;
let s = "hello, world".to_string();
let s1: &str = s;
}
```
@ -135,7 +135,7 @@ fn main() {
unicode_codepoint, character_name );
// 还能使用 \ 来连接多行字符串
let long_string = "String literals
let long_string = "String literals
can span multiple lines.
The linebreak and indentation here \
can be escaped too!";
@ -247,10 +247,10 @@ fn main() {
```rust
use utf8_slice;
fn main() {
let s = "The 🚀 goes to the 🌑!";
let s = "The 🚀 goes to the 🌑!";
let rocket = utf8_slice::slice(s, 4, 5);
// 结果是 "🚀"
let rocket = utf8_slice::slice(s, 4, 5);
// 结果是 "🚀"
}
```

View File

@ -16,8 +16,8 @@ fn main() {
// 修改合适的地方,让代码工作
fn main() {
let t = ("i", "am", "sunface");
assert_eq!(t.1, "sunface");
let t = ("i", "am", "sunface");
assert_eq!(t.1, "sunface");
}
```
@ -64,11 +64,11 @@ fn main() {
```rust,editable
fn main() {
// 填空,需要稍微计算下
let (x, y) = sum_multiply(__);
// 填空,需要稍微计算下
let (x, y) = sum_multiply(__);
assert_eq!(x, 5);
assert_eq!(y, 6);
assert_eq!(x, 5);
assert_eq!(y, 6);
}
fn sum_multiply(nums: (i32, i32)) -> (i32, i32) {