Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What implicit numeric conversions does Rust support?

On page 51 of "Programming Rust" by Jim Blandy & Jason Orendorff the authors state,

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

Why "almost"? What implicit numeric conversions will Rust perform?

like image 798
NO WAR WITH RUSSIA Avatar asked Nov 06 '22 14:11

NO WAR WITH RUSSIA


1 Answers

Like the comments above I don't know of any such implicit conversion and couldn't find an example, but the Rust by example book states the following about type casts

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

There is/was a Pre-RFC where this topic got discussed in more detail showing the pro/con arguments about why Rust should/n't have this feature.

For further information you may have a look at the From and Into traits.

like image 56
Jarrrkob Avatar answered Dec 05 '22 14:12

Jarrrkob