mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-06-23 04:29:41 +00:00
add solutions for basic-types, fix errors
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
# 字符、布尔、单元类型
|
||||
|
||||
### 字符
|
||||
🌟
|
||||
1. 🌟
|
||||
```rust, editable
|
||||
|
||||
use std::mem::size_of_val;
|
||||
@ -14,7 +14,7 @@ fn main() {
|
||||
}
|
||||
```
|
||||
|
||||
🌟
|
||||
2. 🌟
|
||||
```rust, editable
|
||||
|
||||
fn main() {
|
||||
@ -28,7 +28,7 @@ fn print_char(c : char) {
|
||||
```
|
||||
|
||||
### 布尔
|
||||
🌟
|
||||
3. 🌟
|
||||
```rust, editable
|
||||
|
||||
// 让 println! 工作
|
||||
@ -42,7 +42,7 @@ fn main() {
|
||||
}
|
||||
```
|
||||
|
||||
🌟
|
||||
4. 🌟
|
||||
```rust, editable
|
||||
|
||||
fn main() {
|
||||
@ -54,7 +54,7 @@ fn main() {
|
||||
|
||||
|
||||
### 单元类型
|
||||
🌟🌟
|
||||
5. 🌟🌟
|
||||
```rust,editable
|
||||
|
||||
// 让代码工作,但不要修改 `implicitly_ret_unit` !
|
||||
@ -75,7 +75,7 @@ fn explicitly_ret_unit() -> () {
|
||||
}
|
||||
```
|
||||
|
||||
🌟🌟 单元类型占用的内存大小是多少?
|
||||
6. 🌟🌟 单元类型占用的内存大小是多少?
|
||||
```rust,editable
|
||||
|
||||
// 让代码工作:修改 `assert!` 中的 `4`
|
||||
|
@ -5,7 +5,7 @@
|
||||
fn main() {
|
||||
// 不要修改下面两行代码!
|
||||
let (x, y) = (1, 2);
|
||||
let s = sum(1, 2);
|
||||
let s = sum(x, y);
|
||||
|
||||
assert_eq!(s, 3);
|
||||
}
|
||||
@ -29,9 +29,10 @@ fn print() -> i32 {
|
||||
```
|
||||
|
||||
|
||||
🌟🌟
|
||||
🌟🌟🌟
|
||||
|
||||
```rust,editable
|
||||
// 用两种方法求解
|
||||
fn main() {
|
||||
never_return();
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ fn main() {
|
||||
### 练习
|
||||
🌟🌟
|
||||
```rust,editable
|
||||
// 使用两种方法修改内部的 {} 中的内容
|
||||
// 使用两种方法让代码工作起来
|
||||
fn main() {
|
||||
let v = {
|
||||
let mut x = 1;
|
||||
@ -51,7 +51,10 @@ fn main() {
|
||||
🌟
|
||||
```rust,editable
|
||||
|
||||
fn main() {}
|
||||
fn main() {
|
||||
let s = sum(1 , 2);
|
||||
assert_eq!(s, 3);
|
||||
}
|
||||
|
||||
fn sum(x: i32, y: i32) -> i32 {
|
||||
x + y;
|
||||
|
Reference in New Issue
Block a user