rgb/
inherent_impls.rs

1use crate::{Abgr, Argb, Bgr, Bgra, Grb, Rgb, Rgba};
2use crate::formats::gray_a::GrayA;
3use crate::formats::gray::Gray_v08;
4#[cfg(feature = "unstable-experimental")]
5use crate::formats::gray::Gray_v09;
6use crate::formats::gray_alpha::GrayAlpha_v08;
7
8macro_rules! inherent_impls {
9    ($name:ident, $new_fn:ident, [$($field:tt $var:ident),*]) => {
10        impl<T: Copy> $name<T> {
11            #[doc=concat!("Creates a new [`", stringify!($name), "`] pixel type from its components.")]
12            ///
13            /// Alternatively, you can use struct literal syntax to
14            /// create the new pixel type:
15            ///```not_rust
16            #[doc=concat!("use rgb::", stringify!($name), ";")]
17            ///
18            #[doc=concat!("let pixel = ", stringify!($name), " {", stringify!($($field: $var),*), "};")]
19            ///```
20            pub const fn $new_fn($($var: T),*) -> Self {
21                Self {$($field: $var),*}
22            }
23        }
24    }
25}
26
27inherent_impls!(Rgb, new, [r red, g green, b blue]);
28inherent_impls!(Bgr, new_bgr, [b blue, g green, r red]);
29inherent_impls!(Grb, new_grb, [g green, r red, b blue]);
30
31inherent_impls!(Gray_v08, new, [0 value]);
32#[cfg(feature = "unstable-experimental")]
33inherent_impls!(Gray_v09, new, [v value]);
34
35inherent_impls!(Rgba, new, [r red, g green, b blue, a alpha]);
36inherent_impls!(Argb, new_argb, [a alpha, r red, g green, b blue]);
37inherent_impls!(Bgra, new_bgra, [b blue, g green, r red, a alpha]);
38inherent_impls!(Abgr, new_abgr, [a alpha, b blue, g green, r red]);
39inherent_impls!(GrayA, new, [v value, a alpha]);
40
41inherent_impls!(GrayAlpha_v08, new, [0 value, 1 alpha]);