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

Make more Color constructors const fn #14996

Closed
wants to merge 1 commit into from
Closed

Conversation

arendjr
Copy link
Contributor

@arendjr arendjr commented Aug 31, 2024

Objective

I regularly copy-paste color codes to my game and try to use them in const values. These color codes are often in hex format, so converting them to floating points is annoying. Color::srgb_u8() provides a relative convenient alternative, except it's not a const fn.

Solution

This PR makes the Color::srgb_u8() and Color::srgba_u8() constructors const fns, making their use easier in constants.

Testing

I think this is one of those cases where we can say, if it compiles, it works :)

@arendjr
Copy link
Contributor Author

arendjr commented Aug 31, 2024

Ah, nevermind. I had overlooked the issue with floating point arithmatic in const fn :(

@arendjr arendjr closed this Aug 31, 2024
@Luracasmus
Copy link
Contributor

Ah, nevermind. I had overlooked the issue with floating point arithmatic in const fn :(

Will this be fixed by rust-lang/rust#128596 ?

I really like the idea of making more of Bevy const

@arendjr
Copy link
Contributor Author

arendjr commented Sep 2, 2024

Sounds like it would! I don’t actually know what’s Bevy’s policy on supporting older Rust compilers, but it would be great if we could have this soon(ish).

@Luracasmus
Copy link
Contributor

According to the README, Bevy's MSRV is close to the latest release, so this might even be able to be merged almost right away when 1.82 becomes stable!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants