Hacker News new | ask | show | jobs
by game-of-throws 1416 days ago

  let numbers = [0, 1, 2];
  let doubled = numbers.map(|x| x * 2);
You wouldn't want to have to explicitly type out the length of the second array.
1 comments

That isn't really inferring the size of the array though. [T; N]::map(impl FnMut(T) -> U) defines its return type as [U; N]. N is fixed at the original array literal.

https://doc.rust-lang.org/std/primitive.array.html

It's inferring it from the array literal in the first place, but it is a different kind of inference from the original one. But I think that's what the question was asking for:

> What's a sane/legit use case of such inferring in general?

Depends how you interpret "such inferring"

It's inferring the size of `doubled`