basic/base-type/function #640
Replies: 50 comments 84 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.
-
练习题有点超纲了 |
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.
-
这里没有讲到发散函数,但是练习题里面涉及到相关知识点~是不是漏了? |
Beta Was this translation helpful? Give feedback.
-
遇到了一个困惑,在 fn never_return_fn() -> !{} 的实现里,看到 solution 里面写了 panic!() 或者 painc!(); |
Beta Was this translation helpful? Give feedback.
-
有符号整数和无符号整数现在分别还有 i128 和 u128 两个类型· |
Beta Was this translation helpful? Give feedback.
-
good,学习了,上次遇到过这个问题 |
Beta Was this translation helpful? Give feedback.
-
简单易懂,我爱死这作者了 |
Beta Was this translation helpful? Give feedback.
-
或许数字类型可以标注的详细点i128 & u128 (其他语言过来的,默认最高8字节,虽然在后续的章节有描述,但是多标注一处也没啥坏处,有些人还是比较爱看综述) |
Beta Was this translation helpful? Give feedback.
-
一个建议,说类型的时候建议加上英文名,比如 布尔类型(bool),这样可以和实际的代码呼应上 |
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