Casting operator
as
is a binary operator.
Accepts
- Expression of any type
- Expression of the same or another integer type
Returns the casted value.
Casting allowed:
- from integer to integer
- from enum to integer
- to the same type (no effect, no errors)
enum Order {
First = 1,
}
let a = 1; // inferred as u8
let b = a as i8; // explicit casting to the opposite sign
let c: u8 = Order::First; // implicit casting to an integer