rustHow to cast box in Rust
Casting in Rust is the process of converting a value of one type to another type. This can be done using the as
keyword.
let x = 5;
let y = x as i32;
The above code will convert the value of x
from an i32
to an i32
. The output of the code will be:
5
The code consists of the following parts:
let x = 5;
- This declares a variablex
with the value5
.let y = x as i32;
- This casts the value ofx
from ani32
to ani32
.
Helpful links
Related
More of Rust
- Hashshet example in Rust
- How to convert Rust bytes to hex?
- How to convert a Rust HashMap to a JSON string?
- How to convert a Rust HashMap to JSON?
- How to get the last element of a Rust slice?
- How to use non-capturing groups in Rust regex?
- How to use groups in a Rust regex?
- How to match the end of a line in a Rust regex?
- How to escape dots with regex in Rust?
- How to use regex to match a group in Rust?
See more codes...