| 1 | macro_rules! impl_reference_component_methods { |
| 2 | ( $self_ty: ident , [$($element: ident),+] $(, $phantom: ident)?) => { |
| 3 | impl_reference_component_methods!($self_ty<>, [$($element),+] $(, $phantom)?); |
| 4 | }; |
| 5 | ( $self_ty: ident < $($phantom_ty: ident)? > , [$($element: ident),+] $(, $phantom: ident)?) => { |
| 6 | impl<$($phantom_ty,)? T> $self_ty<$($phantom_ty,)? &T> { |
| 7 | /// Get an owned, copied version of this color. |
| 8 | #[inline] |
| 9 | pub fn copied(&self) -> $self_ty<$($phantom_ty,)? T> |
| 10 | where |
| 11 | T: Copy, |
| 12 | { |
| 13 | $self_ty { |
| 14 | $($element: *self.$element,)+ |
| 15 | $($phantom: core::marker::PhantomData,)? |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | /// Get an owned, cloned version of this color. |
| 20 | #[inline] |
| 21 | pub fn cloned(&self) -> $self_ty<$($phantom_ty,)? T> |
| 22 | where |
| 23 | T: Clone, |
| 24 | { |
| 25 | $self_ty { |
| 26 | $($element: self.$element.clone(),)+ |
| 27 | $($phantom: core::marker::PhantomData,)? |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | impl<$($phantom_ty,)? T> $self_ty<$($phantom_ty,)? &mut T> { |
| 33 | /// Update this color with new values. |
| 34 | #[inline] |
| 35 | pub fn set(&mut self, value: $self_ty<$($phantom_ty,)? T>) { |
| 36 | $(*self.$element = value.$element;)+ |
| 37 | } |
| 38 | |
| 39 | /// Borrow this color's components as shared references. |
| 40 | #[inline] |
| 41 | pub fn as_refs(&self) -> $self_ty<$($phantom_ty,)? &T> { |
| 42 | $self_ty { |
| 43 | $($element: &*self.$element,)+ |
| 44 | $($phantom: core::marker::PhantomData,)? |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /// Get an owned, copied version of this color. |
| 49 | #[inline] |
| 50 | pub fn copied(&self) -> $self_ty<$($phantom_ty,)? T> |
| 51 | where |
| 52 | T: Copy, |
| 53 | { |
| 54 | $self_ty { |
| 55 | $($element: *self.$element,)+ |
| 56 | $($phantom: core::marker::PhantomData,)? |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /// Get an owned, cloned version of this color. |
| 61 | #[inline] |
| 62 | pub fn cloned(&self) -> $self_ty<$($phantom_ty,)? T> |
| 63 | where |
| 64 | T: Clone, |
| 65 | { |
| 66 | $self_ty { |
| 67 | $($element: self.$element.clone(),)+ |
| 68 | $($phantom: core::marker::PhantomData,)? |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | impl<$($phantom_ty,)? T, A> crate::Alpha<$self_ty<$($phantom_ty,)? &T>, &A> { |
| 74 | /// Get an owned, copied version of this color. |
| 75 | #[inline] |
| 76 | pub fn copied(&self) -> crate::Alpha<$self_ty<$($phantom_ty,)? T>, A> |
| 77 | where |
| 78 | T: Copy, |
| 79 | A: Copy, |
| 80 | { |
| 81 | crate::Alpha{color: self.color.copied(), alpha: *self.alpha} |
| 82 | } |
| 83 | |
| 84 | /// Get an owned, cloned version of this color. |
| 85 | #[inline] |
| 86 | pub fn cloned(&self) -> crate::Alpha<$self_ty<$($phantom_ty,)? T>, A> |
| 87 | where |
| 88 | T: Clone, |
| 89 | A: Clone, |
| 90 | { |
| 91 | crate::Alpha{color: self.color.cloned(), alpha: self.alpha.clone()} |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | impl<$($phantom_ty,)? T, A> crate::Alpha<$self_ty<$($phantom_ty,)? &mut T>, &mut A> { |
| 96 | /// Update this color with new values. |
| 97 | #[inline] |
| 98 | pub fn set(&mut self, value: crate::Alpha<$self_ty<$($phantom_ty,)? T>, A>) { |
| 99 | self.color.set(value.color); |
| 100 | *self.alpha = value.alpha; |
| 101 | } |
| 102 | |
| 103 | /// Borrow this color's components as shared references. |
| 104 | #[inline] |
| 105 | pub fn as_refs(&self) -> crate::Alpha<$self_ty<$($phantom_ty,)? &T>, &A>{ |
| 106 | crate::Alpha{color: self.color.as_refs(), alpha: &*self.alpha} |
| 107 | } |
| 108 | |
| 109 | /// Get an owned, copied version of this color. |
| 110 | #[inline] |
| 111 | pub fn copied(&self) -> crate::Alpha<$self_ty<$($phantom_ty,)? T>, A> |
| 112 | where |
| 113 | T: Copy, |
| 114 | A: Copy, |
| 115 | { |
| 116 | crate::Alpha{color: self.color.copied(), alpha: *self.alpha} |
| 117 | } |
| 118 | |
| 119 | /// Get an owned, cloned version of this color. |
| 120 | #[inline] |
| 121 | pub fn cloned(&self) -> crate::Alpha<$self_ty<$($phantom_ty,)? T>, A> |
| 122 | where |
| 123 | T: Clone, |
| 124 | A: Clone, |
| 125 | { |
| 126 | crate::Alpha{color: self.color.cloned(), alpha: self.alpha.clone()} |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | macro_rules! impl_reference_component_methods_hue { |
| 133 | ( $self_ty: ident , [$($element: ident),+] $(, $phantom: ident)?) => { |
| 134 | impl_reference_component_methods_hue!($self_ty<>, [$($element),+] $(, $phantom)?); |
| 135 | }; |
| 136 | ( $self_ty: ident < $($phantom_ty: ident)? > , [$($element: ident),+] $(, $phantom: ident)?) => { |
| 137 | impl<$($phantom_ty,)? T> $self_ty<$($phantom_ty,)? &T> { |
| 138 | /// Get an owned, copied version of this color. |
| 139 | #[inline] |
| 140 | pub fn copied(&self) -> $self_ty<$($phantom_ty,)? T> |
| 141 | where |
| 142 | T: Copy, |
| 143 | { |
| 144 | $self_ty { |
| 145 | hue: self.hue.copied(), |
| 146 | $($element: *self.$element,)+ |
| 147 | $($phantom: core::marker::PhantomData,)? |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | /// Get an owned, cloned version of this color. |
| 152 | #[inline] |
| 153 | pub fn cloned(&self) -> $self_ty<$($phantom_ty,)? T> |
| 154 | where |
| 155 | T: Clone, |
| 156 | { |
| 157 | $self_ty { |
| 158 | hue: self.hue.cloned(), |
| 159 | $($element: self.$element.clone(),)+ |
| 160 | $($phantom: core::marker::PhantomData,)? |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | impl<$($phantom_ty,)? T> $self_ty<$($phantom_ty,)? &mut T> { |
| 166 | /// Update this color with new values. |
| 167 | #[inline] |
| 168 | pub fn set(&mut self, value: $self_ty<$($phantom_ty,)? T>) { |
| 169 | self.hue.set(value.hue); |
| 170 | $(*self.$element = value.$element;)+ |
| 171 | } |
| 172 | |
| 173 | /// Borrow this color's components as shared references. |
| 174 | #[inline] |
| 175 | pub fn as_refs(&self) -> $self_ty<$($phantom_ty,)? &T> { |
| 176 | $self_ty { |
| 177 | hue: self.hue.as_ref(), |
| 178 | $($element: &*self.$element,)+ |
| 179 | $($phantom: core::marker::PhantomData,)? |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | /// Get an owned, copied version of this color. |
| 184 | #[inline] |
| 185 | pub fn copied(&self) -> $self_ty<$($phantom_ty,)? T> |
| 186 | where |
| 187 | T: Copy, |
| 188 | { |
| 189 | $self_ty { |
| 190 | hue: self.hue.copied(), |
| 191 | $($element: *self.$element,)+ |
| 192 | $($phantom: core::marker::PhantomData,)? |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | /// Get an owned, cloned version of this color. |
| 197 | #[inline] |
| 198 | pub fn cloned(&self) -> $self_ty<$($phantom_ty,)? T> |
| 199 | where |
| 200 | T: Clone, |
| 201 | { |
| 202 | $self_ty { |
| 203 | hue: self.hue.cloned(), |
| 204 | $($element: self.$element.clone(),)+ |
| 205 | $($phantom: core::marker::PhantomData,)? |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | impl<$($phantom_ty,)? T, A> crate::Alpha<$self_ty<$($phantom_ty,)? &T>, &A> { |
| 211 | /// Get an owned, copied version of this color. |
| 212 | #[inline] |
| 213 | pub fn copied(&self) -> crate::Alpha<$self_ty<$($phantom_ty,)? T>, A> |
| 214 | where |
| 215 | T: Copy, |
| 216 | A: Copy, |
| 217 | { |
| 218 | crate::Alpha{color: self.color.copied(), alpha: *self.alpha} |
| 219 | } |
| 220 | |
| 221 | /// Get an owned, cloned version of this color. |
| 222 | #[inline] |
| 223 | pub fn cloned(&self) -> crate::Alpha<$self_ty<$($phantom_ty,)? T>, A> |
| 224 | where |
| 225 | T: Clone, |
| 226 | A: Clone, |
| 227 | { |
| 228 | crate::Alpha{color: self.color.cloned(), alpha: self.alpha.clone()} |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | impl<$($phantom_ty,)? T, A> crate::Alpha<$self_ty<$($phantom_ty,)? &mut T>, &mut A> { |
| 233 | /// Update this color with new values. |
| 234 | #[inline] |
| 235 | pub fn set(&mut self, value: crate::Alpha<$self_ty<$($phantom_ty,)? T>, A>) { |
| 236 | self.color.set(value.color); |
| 237 | *self.alpha = value.alpha; |
| 238 | } |
| 239 | |
| 240 | /// Borrow this color's components as shared references. |
| 241 | #[inline] |
| 242 | pub fn as_refs(&self) -> crate::Alpha<$self_ty<$($phantom_ty,)? &T>, &A>{ |
| 243 | crate::Alpha{color: self.color.as_refs(), alpha: &*self.alpha} |
| 244 | } |
| 245 | |
| 246 | /// Get an owned, copied version of this color. |
| 247 | #[inline] |
| 248 | pub fn copied(&self) -> crate::Alpha<$self_ty<$($phantom_ty,)? T>, A> |
| 249 | where |
| 250 | T: Copy, |
| 251 | A: Copy, |
| 252 | { |
| 253 | crate::Alpha{color: self.color.copied(), alpha: *self.alpha} |
| 254 | } |
| 255 | |
| 256 | /// Get an owned, cloned version of this color. |
| 257 | #[inline] |
| 258 | pub fn cloned(&self) -> crate::Alpha<$self_ty<$($phantom_ty,)? T>, A> |
| 259 | where |
| 260 | T: Clone, |
| 261 | A: Clone, |
| 262 | { |
| 263 | crate::Alpha{color: self.color.cloned(), alpha: self.alpha.clone()} |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | } |