Skip to content

Commit 6ce01b6

Browse files
committed
Fixes tests for unstable-experimental feature flag
1 parent 1ee08f0 commit 6ce01b6

4 files changed

Lines changed: 45 additions & 31 deletions

File tree

src/formats/gray.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct Gray_v08<T>(
1010
pub T,
1111
);
1212

13-
impl<T: Copy> Gray_v08<T> {
13+
impl<T: Clone> Gray_v08<T> {
1414
/// Reads the `.0` field
1515
///
1616
/// This function isn't necessary, but it is forwards-compatible with the next major version of the RGB crate.
@@ -70,7 +70,7 @@ impl<T> core::ops::Deref for Gray_v08<T> {
7070
}
7171

7272
#[cfg(feature = "unstable-experimental")]
73-
impl<T: Copy> Gray_v09<T> {
73+
impl<T: Clone> Gray_v09<T> {
7474
/// Reads the `.v` field
7575
///
7676
/// This function isn't necessary, but it is forwards-compatible with the next major version of the RGB crate.
@@ -93,6 +93,7 @@ impl<T: Copy> Gray_v09<T> {
9393

9494
#[test]
9595
#[cfg(feature = "unstable-experimental")]
96+
#[allow(deprecated)]
9697
fn swizzle() {
9798
let g = Gray_v08(10u8);
9899
assert_eq!(10, g.v);

src/legacy/internal/convert/mod.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#[allow(deprecated)]
22
use super::pixel::ComponentSlice;
33
use super::pixel::ComponentMap;
4-
use crate::alt::{BGR, BGRA, GRB, Gray, GrayAlpha, ARGB, ABGR};
5-
use crate::{RGB, RGBA};
4+
use crate::alt::{BGR, BGRA, GRB, ARGB, ABGR};
5+
use crate::{RGB, RGBA, Gray, GrayAlpha};
66
use core::{mem, slice};
77

88
mod array;
@@ -288,9 +288,9 @@ impl<T: Clone> From<Gray<T>> for RGB<T> {
288288
#[allow(deprecated)]
289289
fn from(other: Gray<T>) -> Self {
290290
Self {
291-
r: other.0.clone(),
292-
g: other.0.clone(),
293-
b: other.0,
291+
r: other.clone().value(),
292+
g: other.clone().value(),
293+
b: other.value(),
294294
}
295295
}
296296
}
@@ -300,23 +300,23 @@ impl<T: Clone> From<Gray<T>> for RGBA<T, u8> {
300300
#[allow(deprecated)]
301301
fn from(other: Gray<T>) -> Self {
302302
Self {
303-
r: other.0.clone(),
304-
g: other.0.clone(),
305-
b: other.0,
303+
r: other.clone().value(),
304+
g: other.clone().value(),
305+
b: other.value(),
306306
a: 255,
307307
}
308308
}
309309
}
310310

311-
impl<T: Clone, A> From<GrayAlpha<T, A>> for RGBA<T, A> {
311+
impl<T: Clone, A: Clone> From<GrayAlpha<T, A>> for RGBA<T, A> {
312312
#[inline(always)]
313313
#[allow(deprecated)]
314314
fn from(other: GrayAlpha<T, A>) -> Self {
315315
Self {
316-
r: other.0.clone(),
317-
g: other.0.clone(),
318-
b: other.0,
319-
a: other.1,
316+
r: other.v.clone(),
317+
g: other.v.clone(),
318+
b: other.v.clone(),
319+
a: other.a.clone(),
320320
}
321321
}
322322
}

src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ pub use formats::bgr::Bgr;
7272
pub use formats::bgra::Bgra;
7373
#[cfg(not(feature = "unstable-experimental"))]
7474
pub use formats::gray_alpha::GrayAlpha_v08 as GrayAlpha;
75+
#[cfg(feature = "unstable-experimental")]
76+
#[deprecated(note = "Renamed to GrayA")]
77+
pub use formats::gray_a::GrayA as GrayAlpha;
7578
#[cfg(not(feature = "unstable-experimental"))]
7679
pub use formats::gray::Gray_v08 as Gray;
80+
#[cfg(feature = "unstable-experimental")]
81+
pub use formats::gray::Gray_v09 as Gray;
7782
pub use formats::grb::Grb;
7883
pub use formats::rgb::Rgb;
7984
pub use formats::rgba::Rgba;
@@ -122,9 +127,6 @@ pub use formats::rgba::Rgba as RGBA;
122127
/// Incompatible replacement for the `GrayAlpha` type
123128
pub use formats::gray_a::GrayA;
124129

125-
#[cfg(feature = "unstable-experimental")]
126-
pub use formats::gray::Gray_v09 as Gray;
127-
128130
/// 8-bit RGB
129131
///
130132
/// The colorspace is technically undefined, but generally sRGB is assumed.

tests/v08.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ fn shared_impl() {
154154

155155
#[test]
156156
#[allow(deprecated)]
157-
fn gray() {
158-
use rgb::alt::*;
157+
#[cfg(not(feature = "unstable-experimental"))]
158+
fn gray_into() {
159+
use rgb::alt::*;
159160

160161
let rgb: rgb::RGB<_> = Gray(1).into();
161162
assert_eq!(rgb.r, 1);
@@ -167,6 +168,12 @@ fn gray() {
167168
assert_eq!(rgba.g, 1);
168169
assert_eq!(rgba.b, 1);
169170
assert_eq!(rgba.a, 255);
171+
}
172+
173+
#[test]
174+
#[allow(deprecated)]
175+
fn gray() {
176+
use rgb::alt::*;
170177

171178
let g: GRAY8 = 200.into();
172179
let g = g.map(|c| c / 2);
@@ -190,18 +197,22 @@ fn gray() {
190197
assert_eq!(<_>::as_slice(&[Gray(1u16), Gray(2)][..]), &[1, 2]);
191198
assert_eq!(<_>::as_slice(&[GrayAlpha(1u16, 2), GrayAlpha(3, 4)][..]), &[1, 2, 3, 4]);
192199

193-
let rgba: rgb::RGBA<_> = ga.into();
194-
assert_eq!(rgba.r, 1);
195-
assert_eq!(rgba.g, 1);
196-
assert_eq!(rgba.b, 1);
197-
assert_eq!(rgba.a, 2);
200+
#[cfg(not(feature = "unstable-experimental"))]
201+
{
198202

199-
let ga: GRAYA16 = GrayAlpha(1, 2);
200-
let rgba: rgb::RGBA<u16, u16> = ga.into();
201-
assert_eq!(rgba.r, 1);
202-
assert_eq!(rgba.g, 1);
203-
assert_eq!(rgba.b, 1);
204-
assert_eq!(rgba.a, 2);
203+
let rgba: rgb::RGBA<_> = ga.into();
204+
assert_eq!(rgba.r, 1);
205+
assert_eq!(rgba.g, 1);
206+
assert_eq!(rgba.b, 1);
207+
assert_eq!(rgba.a, 2);
208+
209+
let ga: GRAYA16 = GrayAlpha(1, 2);
210+
let rgba: rgb::RGBA<u16, u16> = ga.into();
211+
assert_eq!(rgba.r, 1);
212+
assert_eq!(rgba.g, 1);
213+
assert_eq!(rgba.b, 1);
214+
assert_eq!(rgba.a, 2);
215+
}
205216
}
206217

207218
mod ops {

0 commit comments

Comments
 (0)