在 "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/