Make some associated functions of Color const (#16091)

# Objective
Make the following functions `const` that will be useful to define
colors as constants.

- `Color::srgb_from_array`
- `Color::srgba_u8`
- `Color::srgb_u8`

The last two require Rust 1.82.0.

## Solution
- Make them `const`
- Change MSRV to 1.82.0

## Testing
I tested bevy_color only. My machine does not have enough RAM capacity
to test the whole bevy.

`cargo test -p bevy_color`
This commit is contained in:
mamekoro 2024-10-28 12:26:35 +09:00 committed by GitHub
parent 78a4bea3d7
commit 4b0efda354
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View file

@ -10,7 +10,7 @@ keywords = ["game", "engine", "gamedev", "graphics", "bevy"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
repository = "https://github.com/bevyengine/bevy" repository = "https://github.com/bevyengine/bevy"
documentation = "https://docs.rs/bevy" documentation = "https://docs.rs/bevy"
rust-version = "1.81.0" rust-version = "1.82.0"
[workspace] [workspace]
exclude = [ exclude = [

View file

@ -123,7 +123,7 @@ impl Color {
} }
/// Reads an array of floats to creates a new [`Color`] object storing a [`Srgba`] color with an alpha of 1.0. /// Reads an array of floats to creates a new [`Color`] object storing a [`Srgba`] color with an alpha of 1.0.
pub fn srgb_from_array(array: [f32; 3]) -> Self { pub const fn srgb_from_array(array: [f32; 3]) -> Self {
Self::Srgba(Srgba { Self::Srgba(Srgba {
red: array[0], red: array[0],
green: array[1], green: array[1],
@ -143,7 +143,7 @@ impl Color {
/// Creates a new [`Color`] object storing a [`Srgba`] color from [`u8`] values. /// Creates a new [`Color`] object storing a [`Srgba`] color from [`u8`] values.
/// ///
/// A value of 0 is interpreted as 0.0, and a value of 255 is interpreted as 1.0. /// A value of 0 is interpreted as 0.0, and a value of 255 is interpreted as 1.0.
pub fn srgba_u8(red: u8, green: u8, blue: u8, alpha: u8) -> Self { pub const fn srgba_u8(red: u8, green: u8, blue: u8, alpha: u8) -> Self {
Self::Srgba(Srgba { Self::Srgba(Srgba {
red: red as f32 / 255.0, red: red as f32 / 255.0,
green: green as f32 / 255.0, green: green as f32 / 255.0,
@ -163,7 +163,7 @@ impl Color {
/// Creates a new [`Color`] object storing a [`Srgba`] color from [`u8`] values with an alpha of 1.0. /// Creates a new [`Color`] object storing a [`Srgba`] color from [`u8`] values with an alpha of 1.0.
/// ///
/// A value of 0 is interpreted as 0.0, and a value of 255 is interpreted as 1.0. /// A value of 0 is interpreted as 0.0, and a value of 255 is interpreted as 1.0.
pub fn srgb_u8(red: u8, green: u8, blue: u8) -> Self { pub const fn srgb_u8(red: u8, green: u8, blue: u8) -> Self {
Self::Srgba(Srgba { Self::Srgba(Srgba {
red: red as f32 / 255.0, red: red as f32 / 255.0,
green: green as f32 / 255.0, green: green as f32 / 255.0,