diff --git a/en/src/basic-types/functions.md b/en/src/basic-types/functions.md index 0c5faf5..83910e1 100644 --- a/en/src/basic-types/functions.md +++ b/en/src/basic-types/functions.md @@ -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 + +} +``` \ No newline at end of file diff --git a/zh-CN/src/basic-types/functions.md b/zh-CN/src/basic-types/functions.md index 0c5faf5..4ee0b82 100644 --- a/zh-CN/src/basic-types/functions.md +++ b/zh-CN/src/basic-types/functions.md @@ -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() -> ! { + // 实现这个函数,不要修改函数签名! + +} +``` \ No newline at end of file