Skip to content

Commit 4b0efda

Browse files
authored
Make some associated functions of Color const (bevyengine#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`
1 parent 78a4bea commit 4b0efda

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ keywords = ["game", "engine", "gamedev", "graphics", "bevy"]
1010
license = "MIT OR Apache-2.0"
1111
repository = "https://github.com/bevyengine/bevy"
1212
documentation = "https://docs.rs/bevy"
13-
rust-version = "1.81.0"
13+
rust-version = "1.82.0"
1414

1515
[workspace]
1616
exclude = [

crates/bevy_color/src/color.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl Color {
123123
}
124124

125125
/// Reads an array of floats to creates a new [`Color`] object storing a [`Srgba`] color with an alpha of 1.0.
126-
pub fn srgb_from_array(array: [f32; 3]) -> Self {
126+
pub const fn srgb_from_array(array: [f32; 3]) -> Self {
127127
Self::Srgba(Srgba {
128128
red: array[0],
129129
green: array[1],
@@ -143,7 +143,7 @@ impl Color {
143143
/// Creates a new [`Color`] object storing a [`Srgba`] color from [`u8`] values.
144144
///
145145
/// A value of 0 is interpreted as 0.0, and a value of 255 is interpreted as 1.0.
146-
pub fn srgba_u8(red: u8, green: u8, blue: u8, alpha: u8) -> Self {
146+
pub const fn srgba_u8(red: u8, green: u8, blue: u8, alpha: u8) -> Self {
147147
Self::Srgba(Srgba {
148148
red: red as f32 / 255.0,
149149
green: green as f32 / 255.0,
@@ -163,7 +163,7 @@ impl Color {
163163
/// Creates a new [`Color`] object storing a [`Srgba`] color from [`u8`] values with an alpha of 1.0.
164164
///
165165
/// A value of 0 is interpreted as 0.0, and a value of 255 is interpreted as 1.0.
166-
pub fn srgb_u8(red: u8, green: u8, blue: u8) -> Self {
166+
pub const fn srgb_u8(red: u8, green: u8, blue: u8) -> Self {
167167
Self::Srgba(Srgba {
168168
red: red as f32 / 255.0,
169169
green: green as f32 / 255.0,

0 commit comments

Comments
 (0)