commit
ac88c9cccf
|
@ -22,7 +22,7 @@ fn main() {
|
|||
|
||||
// Fix the error with at least two solutions
|
||||
fn main() {
|
||||
let s: Box<str> = "hello, world".into();
|
||||
let s: Box<str> = "hello, world".into();
|
||||
greetings(s)
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -102,7 +102,7 @@ Opsite to the seldom using of `str`, `&str` and `String` are used everywhere!
|
|||
|
||||
// Fix error with at least two solutions
|
||||
fn main() {
|
||||
let s = "hello, world";
|
||||
let s = "hello, world";
|
||||
greetings(s)
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ fn greetings(s: String) {
|
|||
|
||||
// Use two approaches to fix the error and without adding a new line
|
||||
fn main() {
|
||||
let s = "hello, world".to_string();
|
||||
let s = "hello, world".to_string();
|
||||
let s1: &str = s;
|
||||
|
||||
println!("Success!");
|
||||
|
|
|
@ -173,7 +173,7 @@ fn main() {
|
|||
fn main() {
|
||||
let mut s = String::new();
|
||||
|
||||
let update_string = |str| s.push_str(str);
|
||||
let update_string = |str| s.push_str(str);
|
||||
|
||||
exec(update_string);
|
||||
|
||||
|
@ -260,7 +260,7 @@ move closures may still implement `Fn` or `FnMut`, even though they capture vari
|
|||
fn main() {
|
||||
let s = String::new();
|
||||
|
||||
let update_string = move || println!("{}",s);
|
||||
let update_string = move || println!("{}",s);
|
||||
|
||||
exec(update_string);
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ The following code also has no error:
|
|||
fn main() {
|
||||
let s = String::new();
|
||||
|
||||
let update_string = move || println!("{}",s);
|
||||
let update_string = move || println!("{}",s);
|
||||
|
||||
exec(update_string);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ fn main() {
|
|||
|
||||
// Fill the blanks in the code to make it compile
|
||||
fn main() {
|
||||
let __ = 1;
|
||||
let __ = 1;
|
||||
__ += 2;
|
||||
|
||||
assert_eq!(x, 3);
|
||||
|
@ -73,7 +73,7 @@ fn main() {
|
|||
|
||||
assert_eq!(x, 12);
|
||||
|
||||
let x = 42;
|
||||
let x = 42;
|
||||
println!("{}", x); // Prints "42".
|
||||
}
|
||||
```
|
||||
|
|
|
@ -10,7 +10,7 @@ fn main() {
|
|||
|
||||
```rust
|
||||
fn main() {
|
||||
let s: Box<str> = "hello, world".into();
|
||||
let s: Box<str> = "hello, world".into();
|
||||
greetings(&s)
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ fn main() {
|
|||
|
||||
```rust
|
||||
fn main() {
|
||||
let mut s = String::from("hello");
|
||||
let mut s = String::from("hello");
|
||||
s.push(',');
|
||||
s.push_str(" world");
|
||||
s += "!";
|
||||
|
@ -83,7 +83,7 @@ fn main() {
|
|||
|
||||
```rust
|
||||
fn main() {
|
||||
let s = "hello, world".to_string();
|
||||
let s = "hello, world".to_string();
|
||||
greetings(s)
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ fn main() {
|
|||
|
||||
```rust
|
||||
fn main() {
|
||||
let s = "hello, world";
|
||||
let s = "hello, world";
|
||||
let s1: &str = s;
|
||||
}
|
||||
```
|
||||
|
|
|
@ -136,7 +136,7 @@ fn main() {
|
|||
fn main() {
|
||||
let mut s = String::new();
|
||||
|
||||
let update_string = |str| s.push_str(str);
|
||||
let update_string = |str| s.push_str(str);
|
||||
|
||||
exec(update_string);
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ fn main() {
|
|||
|
||||
// 使用至少两种方法来修复错误
|
||||
fn main() {
|
||||
let s: Box<str> = "hello, world".into();
|
||||
let s: Box<str> = "hello, world".into();
|
||||
greetings(s)
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -98,7 +98,7 @@ fn main() {
|
|||
|
||||
// 使用至少两种方法来修复错误
|
||||
fn main() {
|
||||
let s = "hello, world";
|
||||
let s = "hello, world";
|
||||
greetings(s)
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ fn greetings(s: String) {
|
|||
|
||||
// 使用两种方法来解决错误,不要新增代码行
|
||||
fn main() {
|
||||
let s = "hello, world".to_string();
|
||||
let s = "hello, world".to_string();
|
||||
let s1: &str = s;
|
||||
}
|
||||
```
|
||||
|
|
|
@ -18,7 +18,7 @@ fn main() {
|
|||
|
||||
// 完形填空,让代码编译
|
||||
fn main() {
|
||||
let __ = 1;
|
||||
let __ = 1;
|
||||
__ += 2;
|
||||
|
||||
println!("x = {}", x);
|
||||
|
@ -69,7 +69,7 @@ fn main() {
|
|||
|
||||
assert_eq!(x, 12);
|
||||
|
||||
let x = 42;
|
||||
let x = 42;
|
||||
println!("{}", x); // 输出 "42".
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue