icu4x
icu4x copied to clipboard
Add CharULE::from_array<N>(chars: [char; N]) -> [CharULE; N]
Add const-evaluable CharULE::from_array<N>(chars: [char; N]) -> [CharULE; N]
. (I'm not sure if const evaluation is powerful enough to do this.)
It is whenever https://doc.rust-lang.org/stable/std/primitive.array.html#method.map stabilizes for const, but not before. We're not really doing to/from ULE conversions over const since traits can't be invoked in const anyway.
I'd prefer we don't do this: it's impossible to do until [T; N]::map()
is stable const; and once that method is stable my recommendation would be to just use it.
This isn't true. We already have pub const fn RawBytesULE::from_array<const N: usize>(arr: [u16; N]) -> [Self; N]
https://unicode-org.github.io/icu4x-docs/doc/zerovec/ule/struct.RawBytesULE.html#method.from_array
It doesn't use map
. It just uses plain index operations, which work in const
.
I'd prefer we don't do this: it's impossible to do until
[T; N]::map()
is stable const; and once that method is stable my recommendation would be to just use it.
When such a function is added, we still can't avoid the necessity of type-specific conversion functions, since it seems unlikely that we'll be able to call trait functions in const in the near term. In other words, we will need one of the following for each ULE type:
-
U::from_array<N>(arr: [T; N]) -> [U; N]
-
U::as_ule_const(t: T) -> U
Related: https://github.com/unicode-org/icu4x/issues/1935