Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes, that is true. If you use a literal array, you get i32 for the element type.

I believe this is because of the signature:

  pub fn from_fn<T, const N: usize, F>(cb: F) -> [T; N] 
  where
      F: FnMut(usize) -> T, 
While T is unconstrained, N is a usize, which is used in the closure, which we then re-use as the element.


OK this is just kinda funny - I was right, but only by accident. For some reason I thought that the literal defaulted to usize not i32. The fact that this path makes my assertion of usize correct is pretty cool though. Thanks for diving into it!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: