mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-08-12 06:24:44 +00:00
according to the idea of gtm-nayan #144, add println!("Success") for each exercise
This commit is contained in:
@@ -12,6 +12,8 @@ fn main() {
|
||||
|
||||
let c2 = '中';
|
||||
assert_eq!(size_of_val(&c2),3);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -33,13 +35,13 @@ fn print_char(c : char) {
|
||||
3. 🌟
|
||||
```rust, editable
|
||||
|
||||
// make the println! work
|
||||
// make println! work
|
||||
fn main() {
|
||||
let _f: bool = false;
|
||||
|
||||
let t = true;
|
||||
if !t {
|
||||
println!("hello, world");
|
||||
println!("Success!")
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -52,6 +54,8 @@ fn main() {
|
||||
let f = true;
|
||||
let t = true && false;
|
||||
assert_eq!(t, f);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -66,6 +70,8 @@ fn main() {
|
||||
|
||||
let v = (2, 3);
|
||||
assert_eq!(v, implicitly_ret_unit())
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
|
||||
fn implicitly_ret_unit() {
|
||||
@@ -86,6 +92,8 @@ use std::mem::size_of_val;
|
||||
fn main() {
|
||||
let unit: () = ();
|
||||
assert!(size_of_val(&unit) == 4);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
|
@@ -8,6 +8,8 @@ fn main() {
|
||||
let s = sum(x, y);
|
||||
|
||||
assert_eq!(s, 3);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
|
||||
fn sum(x, y: i32) {
|
||||
@@ -24,7 +26,7 @@ fn main() {
|
||||
|
||||
// replace i32 with another type
|
||||
fn print() -> i32 {
|
||||
println!("hello,world");
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -33,8 +35,11 @@ fn print() -> i32 {
|
||||
|
||||
```rust,editable
|
||||
// solve it in two ways
|
||||
// DON'T let `println!` works
|
||||
fn main() {
|
||||
never_return();
|
||||
|
||||
println!("Failed!")
|
||||
}
|
||||
|
||||
fn never_return() -> ! {
|
||||
|
@@ -16,6 +16,8 @@ fn main() {
|
||||
y = x;
|
||||
|
||||
let z = 10; // type of z ?
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -25,6 +27,8 @@ fn main() {
|
||||
// fill the blank
|
||||
fn main() {
|
||||
let v: u16 = 38_u8 as __;
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -38,6 +42,8 @@ fn main() {
|
||||
fn main() {
|
||||
let x = 5;
|
||||
assert_eq!("u32".to_string(), type_of(&x));
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
|
||||
// get the type of given variable, return a string representation of the type , e.g "i8", "u8", "i32", "u32"
|
||||
@@ -53,6 +59,8 @@ fn type_of<T>(_: &T) -> String {
|
||||
fn main() {
|
||||
assert_eq!(i8::MAX, __);
|
||||
assert_eq!(u8::MAX, __);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -74,6 +82,8 @@ fn main() {
|
||||
fn main() {
|
||||
let v = 1_024 + 0xff + 0o77 + 0b1111_1111;
|
||||
assert!(v == 1579);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -88,6 +98,8 @@ fn main() {
|
||||
let x = 1_000.000_1; // ?
|
||||
let y: f32 = 0.12; // f32
|
||||
let z = 0.01_f64; // f64
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -97,6 +109,8 @@ fn main() {
|
||||
|
||||
fn main() {
|
||||
assert!(0.1+0.2==0.3);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -126,6 +140,8 @@ use std::ops::{Range, RangeInclusive};
|
||||
fn main() {
|
||||
assert_eq!((1..__), Range{ start: 1, end: 5 });
|
||||
assert_eq!((1..__), RangeInclusive::new(1, 5));
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
|
@@ -35,6 +35,8 @@ fn main() {
|
||||
};
|
||||
|
||||
assert_eq!(v, 3);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -45,6 +47,8 @@ fn main() {
|
||||
let v = (let x = 3);
|
||||
|
||||
assert!(v == 3);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -54,6 +58,8 @@ fn main() {
|
||||
fn main() {
|
||||
let s = sum(1 , 2);
|
||||
assert_eq!(s, 3);
|
||||
|
||||
println!("Success!")
|
||||
}
|
||||
|
||||
fn sum(x: i32, y: i32) -> i32 {
|
||||
|
Reference in New Issue
Block a user