basic/base-type/function #640
Replies: 43 comments 74 replies
-
有些抄袭 Rust in Action 的嫌疑。 |
Beta Was this translation helpful? Give feedback.
-
怎么把十六进制的字符串转整数类型? |
Beta Was this translation helpful? Give feedback.
-
请教下,函数返回这块 从代码风格来讲是用 return 好一些还是用最后一个表达式好一些?
fn add1(a: i32, b: i32) -> i32 {
a + b
}
fn add2(a: i32, b: i32) -> i32 {
return a + b
} |
Beta Was this translation helpful? Give feedback.
-
对于这个函数我有一个疑问。
已知 if xxx {} 这样是一个代码块,是可以用表达式返回值的,那这么写为什么会报错呢。 |
Beta Was this translation helpful? Give feedback.
-
更好吧?能返回x-5应该是return这个语句在起作用? |
Beta Was this translation helpful? Give feedback.
-
fn plus_or_minus(x:i32) -> i32 {
if x > 5 {
return x - 5
}
x + 5
}
fn main() {
let x = plus_or_minus(5);
println!("The value of x is: {}", x);
} vscode 保存的时候,会在return后面加上 |
Beta Was this translation helpful? Give feedback.
-
通过 ; 结尾的表达式返回一个 () 不太理解这句话 😭 |
Beta Was this translation helpful? Give feedback.
-
return加分号和不加分号的区别是什么? |
Beta Was this translation helpful? Give feedback.
-
所以 return 语句的返回值是一个 ! 嘛?看起来这样设计更合理一些 emm. |
Beta Was this translation helpful? Give feedback.
-
parse::() |
Beta Was this translation helpful? Give feedback.
-
但是如果你不幸的以 表达式; 的方式作为函数的最后一行代码,就会报错: 这段话是不是有问题 语句才是;吧 表达式没有; |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
有没有大佬解释下为什么返回值要写成这种形式,我感觉这种形式的返回值可读性很差 |
Beta Was this translation helpful? Give feedback.
-
似乎在写操作系统的时候,发散函数将非常有用? |
Beta Was this translation helpful? Give feedback.
-
看到函数的参数和返回值都需要指定类型,那rust在实际中是不是会和c++一样一般都标明类型,即便有些地方不需要。 |
Beta Was this translation helpful? Give feedback.
-
感觉函数调用才是表达式 |
Beta Was this translation helpful? Give feedback.
-
看到这块感觉kotlin的设计还是受jvm局限了,kotlin里的Nothing就是类似的设计思路 |
Beta Was this translation helpful? Give feedback.
-
这一章节的名字不应该叫基本类型 |
Beta Was this translation helpful? Give feedback.
-
永不返回的发散函数 ! |
Beta Was this translation helpful? Give feedback.
-
loop { |
Beta Was this translation helpful? Give feedback.
-
有个问题,为什么循环函数的返回值可以任意写但能编译通过呢? // 返回! 表示死循环
fn dead_end() -> i32 {
loop {
println!("一直循环下去");
}
} |
Beta Was this translation helpful? Give feedback.
-
练习题有点超纲了 |
Beta Was this translation helpful? Give feedback.
-
如上,把return x - 5 改为 x - 5,为什么会提示 |
Beta Was this translation helpful? Give feedback.
-
如果我有个函数需要传入多个参数都是同类型的参数(a:i32,b:i32,c:i32,...),有类似:(a,b,c...:i32)的简写方法吗 |
Beta Was this translation helpful? Give feedback.
-
let guess = "42".parse().expect("Not a number!"); 这个例子有点熟悉😂 |
Beta Was this translation helpful? Give feedback.
-
话说复数不是包括有理数么,”以及有理数、复数“这句话是不是有错.. |
Beta Was this translation helpful? Give feedback.
-
假如你的函数需要返回一个 u32 值,但是如果你不幸的以 表达式; 的语句形式作为函数的最后一行代码,就会报错: 表达式; 是不是要改成语句啊··表达式有返回 语句没有返回 |
Beta Was this translation helpful? Give feedback.
-
basic/base-type/function
https://course.rs/basic/base-type/function.html
Beta Was this translation helpful? Give feedback.
All reactions