add function.md

This commit is contained in:
sunface 2022-02-25 15:41:07 +08:00
parent 357fa1bc24
commit b7c7424da5
2 changed files with 85 additions and 1 deletions

View File

@ -1 +1,43 @@
# Functions
🌟🌟🌟
```rust,editable
fn main() {
// don't modify the following two lines!
let (x, y) = (1, 2);
let s = sum(1, 2);
assert_eq!(s, 3);
}
fn sum(x, y: i32) {
x + y;
}
```
🌟🌟
```rust,editable
fn main() {
print();
}
// replace i32 with another type
fn print() -> i32 {
println!("hello,world");
}
```
🌟🌟
```rust,editable
fn main() {
never_return();
}
fn never_return() -> ! {
// implement this function, don't modify fn signatures
}
```

View File

@ -1 +1,43 @@
# Functions
# 函数
🌟🌟🌟
```rust,editable
fn main() {
// 不要修改下面两行代码!
let (x, y) = (1, 2);
let s = sum(1, 2);
assert_eq!(s, 3);
}
fn sum(x, y: i32) {
x + y;
}
```
🌟🌟
```rust,editable
fn main() {
print();
}
// 使用另一个类型来替代 i32
fn print() -> i32 {
println!("hello,world");
}
```
🌟🌟
```rust,editable
fn main() {
never_return();
}
fn never_return() -> ! {
// 实现这个函数,不要修改函数签名!
}
```