But the code will not compile, it said that Arc<i32> needs to implement copy trait:
error[E0277]: the trait bound `Arc<i32>: Copy` is not satisfied
--> src/main.rs:10:17
|
10 | i: [None;I]
| ^^^^ the trait `Copy` is not implemented for `Arc<i32>`
|
= note: required for `Option<Arc<i32>>` to implement `Copy`
= note: the `Copy` trait is required because this value will be copied for each element of the array
I seem to know why it needs copy trait for an array initialization, but in my case I only initiate with None, so is there any chance my code could work?
I suppose one (main) advantage of this over array::from_fn is that this allows you to make fn get() itself a const fn, too. Other than that, array::from_fn is probably more readable (than the approach using a const item) and (I assume) shouldn’t make a difference in terms of performance.
It seems that inline_const is an unstable feature and I never know it before, learns every day I like this solution because it allows get function to be a const function.