From 33764aa11c94b75d30ef0793898795401df1caf5 Mon Sep 17 00:00:00 2001 From: bruce <2432001677@qq.com> Date: Fri, 25 Mar 2022 15:43:12 +0800 Subject: [PATCH] fix: ugly identation in compound-types --- en/src/compound-types/slice.md | 10 +++---- en/src/compound-types/string.md | 48 +++++++++++++++--------------- en/src/compound-types/tuple.md | 16 +++++----- zh-CN/src/compound-types/slice.md | 2 +- zh-CN/src/compound-types/string.md | 42 +++++++++++++------------- zh-CN/src/compound-types/tuple.md | 12 ++++---- 6 files changed, 65 insertions(+), 65 deletions(-) diff --git a/en/src/compound-types/slice.md b/en/src/compound-types/slice.md index 2c4c0ec..f535397 100644 --- a/en/src/compound-types/slice.md +++ b/en/src/compound-types/slice.md @@ -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!") } ``` diff --git a/en/src/compound-types/string.md b/en/src/compound-types/string.md index f5b3958..57b2d32 100644 --- a/en/src/compound-types/string.md +++ b/en/src/compound-types/string.md @@ -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 = "hello, world".into(); - greetings(s) + let s: Box = "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 "🚀" } ``` diff --git a/en/src/compound-types/tuple.md b/en/src/compound-types/tuple.md index 3912eb6..da45ccc 100644 --- a/en/src/compound-types/tuple.md +++ b/en/src/compound-types/tuple.md @@ -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) { diff --git a/zh-CN/src/compound-types/slice.md b/zh-CN/src/compound-types/slice.md index c0fdbc5..649a5d9 100644 --- a/zh-CN/src/compound-types/slice.md +++ b/zh-CN/src/compound-types/slice.md @@ -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]); diff --git a/zh-CN/src/compound-types/string.md b/zh-CN/src/compound-types/string.md index 1c060d0..989b65b 100644 --- a/zh-CN/src/compound-types/string.md +++ b/zh-CN/src/compound-types/string.md @@ -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 = "hello, world".into(); - greetings(s) + let s: Box = "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); + // 结果是 "🚀" } ``` diff --git a/zh-CN/src/compound-types/tuple.md b/zh-CN/src/compound-types/tuple.md index 840f637..ad8d6bf 100644 --- a/zh-CN/src/compound-types/tuple.md +++ b/zh-CN/src/compound-types/tuple.md @@ -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) {