3 ms·
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.
by game-of-throws 4y 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.
- tomjakubowski 4y agoThat 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 https://doc.rust-lang.org/std/primitive.array.html
- brundolf 4y agoIt'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"
- dymk 4y agoIt's inferring the size of `doubled`
- deleted 4y ago[deleted]