Derive Copy for Color4f
@@ -213,7 +213,7 @@ bitflags! {
// TODO: SkRGBA4f
-#[derive(Clone, PartialEq, Debug)]
+#[derive(Copy, Clone, PartialEq, Debug)]
#[repr(C)]
pub struct Color4f {
pub r: f32,
@@ -355,10 +355,7 @@ impl Color4f {
// TODO: FromBytes_RGBA
pub fn to_opaque(&self) -> Self {
- Self {
- a: 1.0,
- ..self.clone()
- }
+ Self { a: 1.0, ..*self }
}
}
@@ -379,6 +376,10 @@ pub mod colors {
pub const MAGENTA: Color4f = Color4f::new(1.0, 0.0, 1.0, 1.0);
}
+#[cfg(test)]
+mod tests {
+ use super::{colors, Color, Color4f};
+
#[test]
#[allow(clippy::float_cmp)]
pub fn color4f_array_access() {
@@ -399,3 +400,10 @@ pub fn color_color4f_conversion() {
let c2 = cf.to_color();
assert_eq!(c, c2);
}
+
+ #[test]
+ pub fn color4f_value_can_be_passed_as_ref() {
+ fn passed_as_ref(_c: impl AsRef<Color4f>) {}
+ passed_as_ref(colors::BLACK);
+ }
+}
