rgb/formats/
gray_alpha.rs1use crate::formats::gray_a::GrayA;
2use core::ops::{Deref, DerefMut};
3
4#[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#[allow(non_camel_case_types)]
14pub struct GrayAlpha_v08<T, A = T>(
15 #[deprecated(note = "Please use the .v field instaed (it's available through the magic of Deref to GrayA type)")]
19 pub T,
20 #[deprecated(note = "Please use the .a field instead (it's available through the magic of Deref to GrayA type)")]
22 pub A,
23);
24
25impl<T: Copy> GrayAlpha_v08<T> {
26 #[allow(deprecated)]
30 pub fn value(self) -> T {
31 self.0
32 }
33
34 #[allow(deprecated)]
38 pub fn value_mut(&mut self) -> &mut T {
39 &mut self.0
40 }
41}
42
43impl<T, A> Deref for GrayAlpha_v08<T, A> {
44 type Target = GrayA<T, A>;
45
46 fn deref(&self) -> &GrayA<T, A> {
48 unsafe {
49 &*(self as *const Self).cast::<GrayA::<T, A>>()
50 }
51 }
52}
53
54impl<T, A> DerefMut for GrayAlpha_v08<T, A> {
55 fn deref_mut(&mut self) -> &mut GrayA<T, A> {
57 unsafe {
58 &mut *(self as *mut Self).cast::<GrayA::<T, A>>()
59 }
60 }
61}
62
63#[test]
64#[allow(deprecated)]
65fn swizzle() {
66 let mut g = GrayAlpha_v08(10u8, 20u8);
67 assert_eq!(10, g.v);
68 assert_eq!(20, g.a);
69 g.a = 7;
70 assert_eq!(10, g.v);
71 assert_eq!(7, g.1);
72}