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 variablexwith the value5.let y = x as i32;- This casts the value ofxfrom ani32to ani32.
Helpful links
Related
More of Rust
- Word boundary example in regex in Rust
- How to get all matches from a Rust regex?
- How to convert a Rust slice of u8 to u32?
- How to create a HashMap of structs in Rust?
- How to check if a Rust HashMap contains a key?
- How to init zero struct in Rust
- How to create a Rust HashMap from a vector of tuples?
- How to get execution time in Rust
- How to replace a capture group using Rust regex?
- How to replace strings using Rust regex?
See more codes...