-
-
Couldn't load subscription status.
- Fork 91
feat: make ColorGenerator const friendly
#146
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
Conversation
|
This is neat, great idea! It never occurred to me that this even could be made |
|
You mentioned Also, it looks like CI might need some fixing. |
I didn't want to pull in extra dependencies unprompted, especially proc macros like
I'll take a look. I only ran |
b745c01 to
7f21034
Compare
|
Ah, still some non- |
7f21034 to
a6b5d12
Compare
|
either that or bump the rust version enough again (I overlooked that previously) if thats okay for you (idk if you have a MSRV policy). I'm not sure about the |
This allows precomputing a set of colors ahead of time (for people
that are into that). To avoid generating the same colors for each
instance, users can leverage the `const_random` crate to properly
seed their generator.
I don't actually know how useful this is. I just saw a "constexpr
all the things" opportunity and wanted to see if there was anything
obvious preventing this.
One usecase I could think about is users wanting to generate a
couple colors ahead of time, give each one semantic meaning and
then use their meaning consistently. Something like this:
```rust
struct ColorPalette {
types: Color,
identifiers: Color,
other: Color,
}
const COLORS: ColorPalette = {
let mut gen = ColorGenerator::new();
ColorPalette {
types: gen.next(),
identifiers: gen.next(),
others: gen.next(),
}
}
```
a6b5d12 to
67561aa
Compare
|
@zesterer I believe this is ready, I just need another CI run again. |
|
Thanks so much! |
|
Thank you for your review patience. |
This allows precomputing a set of colors ahead of time (for people that are into that). To avoid generating the same colors for each instance, users can leverage the
const_randomcrate to properly seed their generator.I don't actually know how useful this is. I just saw a "constexpr all the things" opportunity and wanted to see if there was anything obvious preventing this.
One usecase I could think about is users wanting to generate a couple colors ahead of time, give each one semantic meaning and then use their meaning consistently. Something like this: