习明昊
习明昊

Reputation: 701

How to cast primitive types?

How should I cast primitive types in Rust?

In C-derived languages, one normally does

    int i = 0;
    long j = (long)i;

This does not work in Rust. What should I use instead?

Upvotes: 0

Views: 257

Answers (1)

fjh
fjh

Reputation: 13081

You're looking for the as keyword:

let x: i32 = 5;
let y: u32 = x as u32;

Upvotes: 6

Related Questions