mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-08-11 22:14:47 +00:00
according to the idea of gtm-nayan #144, add println!("Success") for each exercise
This commit is contained in:
@@ -19,6 +19,8 @@ fn main() {
|
||||
|
||||
// modify below to make it work
|
||||
assert!(arr.len() == 4);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -34,6 +36,8 @@ fn main() {
|
||||
// Arrays are stack allocated, `std::mem::size_of_val` return the bytes which array occupies
|
||||
// A char takes 4 byte in Rust: Unicode char
|
||||
assert!(std::mem::size_of_val(&arr) == __);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -47,6 +51,8 @@ fn main() {
|
||||
|
||||
assert!(list[0] == 1);
|
||||
assert!(list.len() == 100);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -56,6 +62,8 @@ fn main() {
|
||||
fn main() {
|
||||
// fix the error
|
||||
let _arr = [1, 2, '3'];
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -68,6 +76,8 @@ fn main() {
|
||||
let ele = arr[1]; // only modify this line to make the code work!
|
||||
|
||||
assert!(ele == 'a');
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -83,6 +93,8 @@ fn main() {
|
||||
|
||||
// but indexing is not safe
|
||||
let _name1 = &names[2];
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
|
||||
```
|
||||
|
@@ -28,6 +28,8 @@ fn main() {
|
||||
// a enum variant can be converted to a integer by `as`
|
||||
assert_eq!(Number::One, Number1::One);
|
||||
assert_eq!(Number1::One, Number2::One);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -45,6 +47,8 @@ enum Message {
|
||||
fn main() {
|
||||
let msg1 = Message::Move{__}; // instantiating with x = 1, y = 2
|
||||
let msg2 = Message::Write(__); // instantiating with "hello, world!"
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -67,6 +71,8 @@ fn main() {
|
||||
} else {
|
||||
panic!("NEVER LET THIS RUN!");
|
||||
}
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
|
@@ -10,6 +10,8 @@ fn main() {
|
||||
let s1: [i32] = arr[0..2];
|
||||
|
||||
let s2: str = "hello, world" as str;
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -26,6 +28,8 @@ fn main() {
|
||||
// modify '6' to make it work
|
||||
// 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) == 6);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -37,6 +41,8 @@ fn main() {
|
||||
// fill the blanks to make the code work
|
||||
let slice: __ = __;
|
||||
assert_eq!(slice, &[2, 3, 4]);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -52,6 +58,8 @@ fn main() {
|
||||
let slice2 = &s[__];
|
||||
|
||||
assert_eq!(slice1, slice2);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -64,6 +72,8 @@ fn main() {
|
||||
let slice = &s[0..2];
|
||||
|
||||
assert!(slice == "你");
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
|
@@ -10,6 +10,8 @@ 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";
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -42,6 +44,8 @@ fn main() {
|
||||
s.push('!');
|
||||
|
||||
assert_eq!(s, "hello, world!");
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -68,7 +72,9 @@ fn main() {
|
||||
// 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!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -113,6 +119,8 @@ fn greetings(s: String) {
|
||||
fn main() {
|
||||
let s = "hello, world".to_string();
|
||||
let s1: &str = s;
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -222,6 +230,8 @@ fn main() {
|
||||
|
||||
let h1 = &s1[3..5];//modify this line to fix the error, tips: `中` takes 3 bytes in UTF8 format
|
||||
assert_eq!(h1, "中");
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
|
@@ -16,6 +16,8 @@ fn main() {
|
||||
name: String::from("sunface"),
|
||||
age,
|
||||
};
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -34,6 +36,8 @@ impl SomeTrait for Unit { }
|
||||
fn main() {
|
||||
let u = Unit;
|
||||
do_something_with_unit(u);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
|
||||
// fill the blank to make the code work
|
||||
@@ -50,6 +54,8 @@ struct Point(i32, i32, i32);
|
||||
fn main() {
|
||||
let v = Point(__, __, __);
|
||||
check_color(v);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
|
||||
fn check_color(p: Color) {
|
||||
@@ -83,6 +89,8 @@ fn main() {
|
||||
|
||||
// fill the lank
|
||||
__ = String::from("sunfei");
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -94,7 +102,9 @@ struct Person {
|
||||
name: String,
|
||||
age: u8,
|
||||
}
|
||||
fn main() {}
|
||||
fn main() {
|
||||
println!("Success!")
|
||||
}
|
||||
|
||||
fn build_person(name: String, age: u8) -> Person {
|
||||
Person {
|
||||
@@ -123,6 +133,8 @@ fn main() {
|
||||
};
|
||||
|
||||
let u2 = set_email(u1);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
|
||||
fn set_email(u: User) -> User {
|
||||
|
@@ -8,6 +8,8 @@ fn main() {
|
||||
let _t1: (u8, (i16, u32)) = (0, (-1, 1));
|
||||
// fill the blanks to make the code work
|
||||
let t: (u8, __, i64, __, __) = (1u8, 2u16, 3i64, "hello", String::from(", world"));
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -18,6 +20,8 @@ fn main() {
|
||||
fn main() {
|
||||
let t = ("i", "am", "sunface");
|
||||
assert_eq!(t.1, "sunface");
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -43,6 +47,8 @@ fn main() {
|
||||
assert_eq!(x, 1);
|
||||
assert_eq!(y, "hello");
|
||||
assert_eq!(z, 6.4);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -57,6 +63,8 @@ fn main() {
|
||||
assert_eq!(x, 3);
|
||||
assert_eq!(y, 1);
|
||||
assert_eq!(z, 2);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -69,6 +77,8 @@ fn main() {
|
||||
|
||||
assert_eq!(x, 5);
|
||||
assert_eq!(y, 6);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
|
||||
fn sum_multiply(nums: (i32, i32)) -> (i32, i32) {
|
||||
|
Reference in New Issue
Block a user