1#[repr(C)]
2#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
4#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
5/// A `Grayscale` pixel (rgb crate v0.8)
6#[allow(non_camel_case_types)]
7pub struct Gray_v08<T>(
8/// Grayscale Component. This field will be renamed to `v`.
9pub T,
10);
1112impl<T: Copy> Gray_v08<T> {
13/// Reads the `.0` field
14 ///
15 /// This function isn't necessary, but it is forwards-compatible with the next major version of the RGB crate.
16pub fn value(self) -> T {
17self.0
18}
1920/// Exposes the `.0` field for writing
21 ///
22 /// This function isn't necessary, but it is forwards-compatible with the next major version of the RGB crate.
23pub fn value_mut(&mut self) -> &mut T {
24&mut self.0
25}
2627/// Add alpha component to this pixel
28#[allow(deprecated)]
29pub fn with_alpha(self, add_alpha_value: T) -> crate::formats::gray_alpha::GrayAlpha_v08<T> {
30crate::formats::gray_alpha::GrayAlpha_v08(self.0, add_alpha_value)
31 }
32}
3334#[cfg(feature = "unstable-experimental")]
35/// A `Grayscale` pixel (rgb crate v0.9)
36///
37/// This is the new gray pixel type as opposed to the legacy gray type
38/// (`rgb::Gray`) which is kept for backwards-compatibility.
39///
40/// # Examples
41///
42/// ```
43/// use rgb::Gray;
44///
45/// let pixel: Gray<u8> = Gray { v: 0 };
46/// ```
47#[allow(non_camel_case_types)]
48#[repr(C)]
49#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
50#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
51#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
52#[doc(alias = "Luma")]
53pub struct Gray_v09<T> {
54/// Grayscale Component
55pub v: T,
56}
5758#[cfg(feature = "unstable-experimental")]
59impl<T> core::ops::Deref for Gray_v08<T> {
60type Target = Gray_v09<T>;
6162fn deref(&self) -> &Gray_v09<T> {
63unsafe {
64&*(self as *const Self as *const Gray_v09::<T>)
65 }
66 }
67}
6869#[cfg(feature = "unstable-experimental")]
70impl<T: Copy> Gray_v09<T> {
71/// Reads the `.v` field
72 ///
73 /// This function isn't necessary, but it is forwards-compatible with the next major version of the RGB crate.
74pub fn value(self) -> T {
75self.v
76 }
7778/// Exposes the `.v` field for writing
79 ///
80 /// This function isn't necessary, but it is forwards-compatible with the next major version of the RGB crate.
81pub fn value_mut(&mut self) -> &mut T {
82&mut self.v
83 }
8485/// Add alpha component to this pixel
86pub fn with_alpha(self, add_alpha_value: T) -> crate::formats::gray_a::GrayA<T> {
87crate::formats::gray_a::GrayA { v: self.v, a: add_alpha_value }
88 }
89}
9091#[test]
92#[cfg(feature = "unstable-experimental")]
93fn swizzle() {
94let g = Gray_v08(10u8);
95assert_eq!(10, g.v);
96assert_eq!(10, g.0);
97}