Skip to content

Commit 13368ac

Browse files
committed
Make a few palette::cast::* functions const fn
1 parent b60a87d commit 13368ac

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

palette/src/cast/array.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,12 @@ where
238238
/// let array3 = <&[_; 3]>::from(&color);
239239
/// ```
240240
#[inline]
241-
pub fn into_array_ref<T>(value: &T) -> &T::Array
241+
pub const fn into_array_ref<T>(value: &T) -> &T::Array
242242
where
243243
T: ArrayCast,
244244
{
245-
assert_eq!(core::mem::size_of::<T::Array>(), core::mem::size_of::<T>());
246-
assert_eq!(
247-
core::mem::align_of::<T::Array>(),
248-
core::mem::align_of::<T>()
249-
);
245+
assert!(core::mem::size_of::<T::Array>() == core::mem::size_of::<T>());
246+
assert!(core::mem::align_of::<T::Array>() == core::mem::align_of::<T>());
250247

251248
let value: *const T = value;
252249

@@ -282,15 +279,12 @@ where
282279
/// let color3 = <&Srgb<u8>>::from(&array);
283280
/// ```
284281
#[inline]
285-
pub fn from_array_ref<T>(value: &T::Array) -> &T
282+
pub const fn from_array_ref<T>(value: &T::Array) -> &T
286283
where
287284
T: ArrayCast,
288285
{
289-
assert_eq!(core::mem::size_of::<T::Array>(), core::mem::size_of::<T>());
290-
assert_eq!(
291-
core::mem::align_of::<T::Array>(),
292-
core::mem::align_of::<T>()
293-
);
286+
assert!(core::mem::size_of::<T::Array>() == core::mem::size_of::<T>());
287+
assert!(core::mem::align_of::<T::Array>() == core::mem::align_of::<T>());
294288

295289
let value: *const T::Array = value;
296290

palette/src/cast/uint.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ where
110110
/// assert_eq!(cast::into_uint_ref(&color), &0xFF17C64C);
111111
/// ```
112112
#[inline]
113-
pub fn into_uint_ref<T>(value: &T) -> &T::Uint
113+
pub const fn into_uint_ref<T>(value: &T) -> &T::Uint
114114
where
115115
T: UintCast,
116116
{
117-
assert_eq!(core::mem::size_of::<T::Uint>(), core::mem::size_of::<T>());
118-
assert_eq!(core::mem::align_of::<T::Uint>(), core::mem::align_of::<T>());
117+
assert!(core::mem::size_of::<T::Uint>() == core::mem::size_of::<T>());
118+
assert!(core::mem::align_of::<T::Uint>() == core::mem::align_of::<T>());
119119

120120
let value: *const T = value;
121121

@@ -133,12 +133,12 @@ where
133133
/// assert_eq!(cast::from_uint_ref::<PackedArgb>(&0xFF17C64C), &color);
134134
/// ```
135135
#[inline]
136-
pub fn from_uint_ref<T>(value: &T::Uint) -> &T
136+
pub const fn from_uint_ref<T>(value: &T::Uint) -> &T
137137
where
138138
T: UintCast,
139139
{
140-
assert_eq!(core::mem::size_of::<T::Uint>(), core::mem::size_of::<T>());
141-
assert_eq!(core::mem::align_of::<T::Uint>(), core::mem::align_of::<T>());
140+
assert!(core::mem::size_of::<T::Uint>() == core::mem::size_of::<T>());
141+
assert!(core::mem::align_of::<T::Uint>() == core::mem::align_of::<T>());
142142

143143
let value: *const T::Uint = value;
144144

0 commit comments

Comments
 (0)