1use crate::formats::gray_a::GrayA;
2use core::ops::Deref;
34#[repr(C)]
5#[cfg_attr(feature = "unstable-experimental", deprecated(note = "renamed to GrayA"))]
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
8#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
9/// A pixel for grayscale value + alpha components (rgb crate v0.8)
10///
11/// Through a `Deref` hack it renames the fields from `.0` and `.1`
12/// to `.v` (value) and `.a` (alpha)
13#[allow(non_camel_case_types)]
14pub struct GrayAlpha_v08<T, A = T>(
15/// Grayscale Component
16 ///
17 /// This field has been renamed to `.v`
18pub T,
19/// Alpha Component. This field has been renamed to `.a`.
20pub A,
21);
2223impl<T: Copy> GrayAlpha_v08<T> {
24/// Reads the `.0` field
25 ///
26 /// This function isn't necessary, but it is forwards-compatible with the next major version of the RGB crate.
27pub fn value(self) -> T {
28self.0
29}
3031/// Exposes the `.0` field for writing
32 ///
33 /// This function isn't necessary, but it is forwards-compatible with the next major version of the RGB crate.
34pub fn value_mut(&mut self) -> &mut T {
35&mut self.0
36}
37}
3839impl<T, A> Deref for GrayAlpha_v08<T, A> {
40type Target = GrayA<T, A>;
4142/// A trick that allows using `.v` and `.a` on the old `GrayAlpha` type.
43fn deref(&self) -> &GrayA<T, A> {
44unsafe {
45&*(self as *const Self as *const GrayA::<T, A>)
46 }
47 }
48}
4950#[test]
51fn swizzle() {
52let g = GrayAlpha_v08(10u8, 20u8);
53assert_eq!(10, g.v);
54assert_eq!(20, g.a);
55}