How can I make a range from 0 to u64::MAX and assign it to a variable like it's done for u32
let n in 0 .. u32::MAX
Then pass n
to a function in a loop.
How can I make a range from 0 to u64::MAX and assign it to a variable like it's done for u32
let n in 0 .. u32::MAX
Then pass n
to a function in a loop.
0..u64::max
will work, Range
accepts any type. Are you sure you want to though? u64::MAX
is 18,446,744,073,709,551,615 (18.446 quintillion), which would take quite a long time to iterate over
error message
expected u32, found u64
Ah, sorry, didn't look at the linked code closely enough.
It seems the issue is that the Vec
expects u32
, so instead of Vec::<u32>::new()
, try Vec::<u64>::new()
, or Vec::new()
and let the compiler figure it out.
(but a Vec
of length u64::MAX
certainly won't work)
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.