mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-06-23 12:39:42 +00:00
Fixed missing semicolons in basic-types, char-bool-unit
This commit is contained in:
@ -4,7 +4,7 @@
|
|||||||
1. 🌟
|
1. 🌟
|
||||||
```rust, editable
|
```rust, editable
|
||||||
|
|
||||||
// make it work
|
// Make it work
|
||||||
use std::mem::size_of_val;
|
use std::mem::size_of_val;
|
||||||
fn main() {
|
fn main() {
|
||||||
let c1 = 'a';
|
let c1 = 'a';
|
||||||
@ -13,14 +13,14 @@ fn main() {
|
|||||||
let c2 = '中';
|
let c2 = '中';
|
||||||
assert_eq!(size_of_val(&c2),3);
|
assert_eq!(size_of_val(&c2),3);
|
||||||
|
|
||||||
println!("Success!")
|
println!("Success!");
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
2. 🌟
|
2. 🌟
|
||||||
```rust, editable
|
```rust, editable
|
||||||
|
|
||||||
// make it work
|
// Make it work
|
||||||
fn main() {
|
fn main() {
|
||||||
let c1 = "中";
|
let c1 = "中";
|
||||||
print_char(c1);
|
print_char(c1);
|
||||||
@ -35,13 +35,13 @@ fn print_char(c : char) {
|
|||||||
3. 🌟
|
3. 🌟
|
||||||
```rust, editable
|
```rust, editable
|
||||||
|
|
||||||
// make println! work
|
// Make println! work
|
||||||
fn main() {
|
fn main() {
|
||||||
let _f: bool = false;
|
let _f: bool = false;
|
||||||
|
|
||||||
let t = true;
|
let t = true;
|
||||||
if !t {
|
if !t {
|
||||||
println!("Success!")
|
println!("Success!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -49,13 +49,13 @@ fn main() {
|
|||||||
4. 🌟
|
4. 🌟
|
||||||
```rust, editable
|
```rust, editable
|
||||||
|
|
||||||
// make it work
|
// Make it work
|
||||||
fn main() {
|
fn main() {
|
||||||
let f = true;
|
let f = true;
|
||||||
let t = true && false;
|
let t = true && false;
|
||||||
assert_eq!(t, f);
|
assert_eq!(t, f);
|
||||||
|
|
||||||
println!("Success!")
|
println!("Success!");
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -64,36 +64,36 @@ fn main() {
|
|||||||
5. 🌟🌟
|
5. 🌟🌟
|
||||||
```rust,editable
|
```rust,editable
|
||||||
|
|
||||||
// make it work, don't modify `implicitly_ret_unit` !
|
// Make it work, don't modify `implicitly_ret_unit` !
|
||||||
fn main() {
|
fn main() {
|
||||||
let _v: () = ();
|
let _v: () = ();
|
||||||
|
|
||||||
let v = (2, 3);
|
let v = (2, 3);
|
||||||
assert_eq!(v, implicitly_ret_unit());
|
assert_eq!(v, implicitly_ret_unit());
|
||||||
|
|
||||||
println!("Success!")
|
println!("Success!");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn implicitly_ret_unit() {
|
fn implicitly_ret_unit() {
|
||||||
println!("I will return a ()")
|
println!("I will return a ()");
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't use this one
|
// Don't use this one
|
||||||
fn explicitly_ret_unit() -> () {
|
fn explicitly_ret_unit() -> () {
|
||||||
println!("I will return a ()")
|
println!("I will return a ()");
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
6. 🌟🌟 what's the size of the unit type?
|
6. 🌟🌟 What's the size of the unit type?
|
||||||
```rust,editable
|
```rust,editable
|
||||||
|
|
||||||
// modify `4` in assert to make it work
|
// Modify `4` in assert to make it work
|
||||||
use std::mem::size_of_val;
|
use std::mem::size_of_val;
|
||||||
fn main() {
|
fn main() {
|
||||||
let unit: () = ();
|
let unit: () = ();
|
||||||
assert!(size_of_val(&unit) == 4);
|
assert!(size_of_val(&unit) == 4);
|
||||||
|
|
||||||
println!("Success!")
|
println!("Success!");
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user