Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CharULE::from_array<N>(chars: [char; N]) -> [CharULE; N] #2491

Closed
hsivonen opened this issue Aug 31, 2022 · 4 comments · Fixed by #3445
Closed

Add CharULE::from_array<N>(chars: [char; N]) -> [CharULE; N] #2491

hsivonen opened this issue Aug 31, 2022 · 4 comments · Fixed by #3445
Assignees
Labels
C-zerovec Component: Yoke, ZeroVec, DataBake discuss Discuss at a future ICU4X-SC meeting

Comments

@hsivonen
Copy link
Member

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.)

@Manishearth
Copy link
Member

Manishearth commented Sep 1, 2022

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.

@sffc
Copy link
Member

sffc commented Sep 1, 2022

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.

@sffc sffc reopened this Sep 1, 2022
@sffc
Copy link
Member

sffc commented Sep 1, 2022

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:

  1. U::from_array<N>(arr: [T; N]) -> [U; N]
  2. U::as_ule_const(t: T) -> U

@sffc sffc added the discuss Discuss at a future ICU4X-SC meeting label Sep 1, 2022
@sffc
Copy link
Member

sffc commented Sep 1, 2022

Related: #1935

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-zerovec Component: Yoke, ZeroVec, DataBake discuss Discuss at a future ICU4X-SC meeting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants