-
Notifications
You must be signed in to change notification settings - Fork 121
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
Suggestion: lookup table construction with const fn #188
Comments
But I wonder if there is any way to manually construct the table, I saw a place where we have a use case to build a two way Map, I wonder if it could be done without duplicating all the stuff. pub(crate) struct NamedColorMap {
name_to_rgba: HashMap<&'static str, [u8; 4]>,
rgba_to_name: HashMap<[u8; 4], &'static str>,
} |
This is theoretically possible, however constifying the map generator code isn't trivial. Have a look. A glance there's a lot of code here that depends on non-const APIs:
It's the trait-based hashing that would be the most difficult to replace right now because we don't have const trait fns. Constifying this would probably require hand-monomorphized code and a different constructor function for each possible key type (deduplicated with macros, sure, but that's suboptimal). |
rust-lang/rfcs#2632 would likely allow this, assuming some trait impls get |
I dont think that a similar RFC is gonna ever come out and be merged in within a year. Maybe #242 is a good step on just making it work with the current hacks that Rust permits. |
Currently lookup tables are contructed with macros, where keys and values are almost literals. With constant functions, one can use a rich set of builtin constant expressions during the construction of lookup tables. For example,
The text was updated successfully, but these errors were encountered: