It seems like this could be a way to make const functions much more powerful. I've seen elsewhere that arbitrary loops aren't allowed in const functions, but I believe in principle the iterator HOFs should be much less likely to do bad things (e.g. map, fold, etc).
An example of what would be ideal to have as const, and in my view, there should be a way to make this const (if I am wrong, please correct me).
pub const fn double_them(xs: &Vec<i32>) -> Vec<i32> {
xs.into_iter().map(|x| 2*x).collect()
}
Currently on a recent nightly this gives:
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
--> src/sfwtools.rs:65:5
|
65 | xs.into_iter().map(|x| 2*x).collect()
| ^^^^^^^^^^^^^^
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
--> src/sfwtools.rs:65:5
|
65 | xs.into_iter().map(|x| 2*x).collect()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
--> src/sfwtools.rs:65:5
|
65 | xs.into_iter().map(|x| 2*x).collect()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors; 2 warnings emitted
There may already be tracking issues for some of these, in which case - I'm sorry if I missed them.