add solutions for basic-types, fix errors

This commit is contained in:
sunface
2022-03-02 16:27:16 +08:00
parent 6be05a6686
commit 59851ca1bb
9 changed files with 211 additions and 26 deletions

View File

@ -1,7 +1,7 @@
# Char, Bool and Unit
### Char
🌟
1. 🌟
```rust, editable
// make it work
@ -15,7 +15,7 @@ fn main() {
}
```
🌟
2. 🌟
```rust, editable
// make it work
@ -30,7 +30,7 @@ fn print_char(c : char) {
```
### Bool
🌟
3. 🌟
```rust, editable
// make the println! work
@ -44,7 +44,7 @@ fn main() {
}
```
🌟
4. 🌟
```rust, editable
// make it work
@ -57,7 +57,7 @@ fn main() {
### Unit type
🌟🌟
5. 🌟🌟
```rust,editable
// make it work, don't modify `implicitly_ret_unit` !
@ -78,7 +78,7 @@ fn explicitly_ret_unit() -> () {
}
```
🌟🌟 what's the size of the unit type?
6. 🌟🌟 what's the size of the unit type?
```rust,editable
// modify `4` in assert to make it work

View File

@ -1,11 +1,11 @@
# Functions
🌟🌟🌟
1. 🌟🌟🌟
```rust,editable
fn main() {
// don't modify the following two lines!
let (x, y) = (1, 2);
let s = sum(1, 2);
let s = sum(x, y);
assert_eq!(s, 3);
}
@ -16,7 +16,7 @@ fn sum(x, y: i32) {
```
🌟🌟
2. 🌟
```rust,editable
fn main() {
print();
@ -29,15 +29,16 @@ fn print() -> i32 {
```
🌟🌟
3. 🌟🌟🌟
```rust,editable
// solve it in two ways
fn main() {
never_return();
}
fn never_return() -> ! {
// implement this function, don't modify fn signatures
// implement this function, don't modify the fn signatures
}
```

View File

@ -25,9 +25,9 @@ fn main() {
```
### Exercises
🌟🌟
1. 🌟🌟
```rust,editable
// make it work with two ways: both modify the inner {}
// make it work with two ways
fn main() {
let v = {
let mut x = 1;
@ -38,7 +38,7 @@ fn main() {
}
```
🌟
2. 🌟
```rust,editable
fn main() {
@ -48,10 +48,13 @@ fn main() {
}
```
🌟
3. 🌟
```rust,editable
fn main() {}
fn main() {
let s = sum(1 , 2);
assert_eq!(s, 3);
}
fn sum(x: i32, y: i32) -> i32 {
x + y;