Tracking issue for try_array_from_fn (original) (raw)
Provides the common use-case of creating custom fallible arrays in a reliable and unified way. Particularly useful for elements that don't implement Copy, Clone or Default.
Public API
// Unstable fn try_from_fn<E, F, T, const N: usize>(cb: F) -> Result<[T; N], E> where F: FnMut(usize) -> Result<T, E>;
Steps / History
- Implementation (Add 'core::array::from_fn' and 'core::array::try_from_fn' #75644)
- Final comment period
- Stabilization PR
Unresolved Questions
Should the callback return indices (Add 'core::array::from_fn' and 'core::array::try_from_fn' #75644 (comment)) ?from_fnandtry_from_fnare very similar torepeat_withandtry_repeat_with(Tracking Issue for core::array::(try_)repeat(_with) (feature array_repeat) #91613), just that they take unary instead of nullary functions. Anyone considering stabilizing these should think about those, and vice versa.