For some of my use cases it would be very interesting that the array's map
function becomes const
at some point. This would allow to preprocess data at compile time. It be especially useful once Option
's const unwrap
, and other basic std
utilities, get stabilized.
Is there a plan for adding that const
to arrays, and if not, what is the blocking factor?
For map
, the main (or perhaps the only) blocking thing is const
closures. Those also need const
traits / trait bounds (if you only have the const
traits, but no const
closures, then map
might already be possible to implement but would be hard to call in const
contexts; e. g. try calling Option::unwrap_or_else
in a const context on nightly using the necessary features.)
Thank you, that makes sense!
The problem is the map function uses iterators under the hood, and to make iterators usable it requires a huge change. We are in the middle of a transition to a better model with const traits and it will be const, it just have to come after we made the transition and make it possible to use iterators in const contexts.