Rust does not support implicit type conversion as many other languages do. However, type conversion in Rust (coercion) can still be performed explicitly in one of these ways:
-
It can be done using the dot operator (
.
) and a very limited type of coercion. -
Primitive type conversion can be performed through the
as
keyword. -
Many standard types and types found in third-party crates contain methods (
parse()
,from()
) that can be used for type conversion. -
Casting C-style and pointers casting can still be performed through the
as
keyword (or specific methods) and completed through unsafe Rust.
Check out our detailed Answer on “How to perform type conversion in Rust.”