Unpacking tuple and casting at the same time

let dim = (300u32, 300u32); // e.g. dimension of screen
let (w, h) = dim;  // I want w and h as f32 
// current solution
let w = w as f32;
let h = h as f32; 

Is there a shorter way?

let (w, h) = (dim.0 as f32, dim.1 as f32);

which is basically just another way to say

let w = dim.0 as f32;
let h = dim.1 as f32;

YMMV whether either of these is preferable to your current code.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.