rust - Rust 支持哪些隐式数字转换?

标签 rust type-conversion

"Programming Rust" by Jim Blandy & Jason Orendorff 的第 51 页上作者说,

Unlike C and C++, Rust performs almost no numeric conversions implicitly.



为什么是“几乎”? Rust 将执行哪些隐式数字转换?

最佳答案

就像上面的评论一样,我不知道任何此类隐式转换,也找不到示例,但是 Rust by example书中陈述了以下关于 type casts 的内容

Rust provides no implicit type conversion (coercion) between primitive types. But, explicit type conversion (casting) can be performed using the as keyword.



有/曾经是 Pre-RFC在这里更详细地讨论了这个主题,展示了关于为什么 Rust 应该/不应该有这个功能的赞成/反对意见。

有关更多信息,您可以查看 From and Into性状。

关于rust - Rust 支持哪些隐式数字转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57485921/

相关文章:

excel - 如何将文本转换为数字?

python - Python 中 float 到分数的转换

c# - 从C#中的列表中选择指定的子类型

c++ - 我是否从 "const char *"正确转换为 "TCHAR*"?

rust - 我什么时候应该在 Rust 中使用特征作为类型?

rust - 有没有办法将时区缩写解析为 Rust 中的时区偏移量?

rust - 在模块中派生可编码特征不起作用

rust - 拥有一些数据和对数据的引用的结构

c# - Int to Decimal Conversion - 在指定位置插入小数点

rust - 为什么在 &mut T 工作时,我不能使用 &mut Box<T> 一次多次借用可变变量?