Skip to content

Commit 3e1035b

Browse files
committed
Reduce the minimum compile time a bit
1 parent d4cae1e commit 3e1035b

29 files changed

+95
-18
lines changed

.github/workflows/ci.yml

+12-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,18 @@ jobs:
2727
override: true
2828
target: thumbv6m-none-eabi
2929
profile: minimal
30-
- uses: actions-rs/cargo@v1
30+
- name: Minimal check
31+
uses: actions-rs/cargo@v1
32+
with:
33+
command: check
34+
args: -v -p palette --no-default-features --features std
35+
- name: find-crate check
36+
uses: actions-rs/cargo@v1
37+
with:
38+
command: check
39+
args: -v -p palette --no-default-features --features "std find-crate"
40+
- name: Default check
41+
uses: actions-rs/cargo@v1
3142
with:
3243
command: check
3344
args: -v --workspace --exclude no_std_test

.vscode/settings.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"bytemuck",
66
"wide"
77
],
8-
"rust-analyzer.assist.importEnforceGranularity": true,
9-
"rust-analyzer.assist.importGranularity": "crate",
10-
"rust-analyzer.assist.importGroup": true
8+
"rust-analyzer.imports.granularity.enforce": true,
9+
"rust-analyzer.imports.granularity.group": "crate",
10+
"rust-analyzer.imports.group.enable": true
1111
}

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ members = [
44
"palette_derive",
55

66
# Test crates
7-
"no_std_test"
7+
"no_std_test",
88
]
9+
resolver = "2"

palette/Cargo.toml

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,28 @@ readme = "README.md"
2121
keywords = ["color", "conversion", "linear", "pixel", "rgb"]
2222
license = "MIT OR Apache-2.0"
2323
edition = "2018"
24+
resolver = "2"
2425
categories = ["graphics", "multimedia::images", "no-std"]
2526
build = "build/main.rs"
2627

2728
[features]
28-
default = ["named_from_str", "named_gradients", "std"]
29+
default = ["named_from_str", "named_gradients", "std", "approx"]
2930
named_from_str = ["named", "phf"]
3031
named = []
3132
named_gradients = ["std"]
3233
random = ["rand"]
3334
serializing = ["serde", "std"]
3435
#ignore in feature test
35-
std = ["approx/std"]
36+
find-crate = ["palette_derive/find-crate"]
37+
std = ["approx?/std"]
3638

3739
[lib]
3840
bench = false
3941

4042
[dependencies]
4143
palette_derive = { version = "0.6.0", path = "../palette_derive" }
4244
fast-srgb8 = "1.0.0"
43-
approx = { version = "0.5", default-features = false }
45+
approx = { version = "0.5", default-features = false, optional = true }
4446
libm = { version = "0.2.1", default-features = false, optional = true }
4547

4648
[dependencies.phf]

palette/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ These features are enabled by default:
4444
* `"named_from_str"` - Enables `named::from_str`, which maps name strings to colors.
4545
* `"named_gradients"`- Enables gradient constants, located in `gradient::named`. This requires the standard library.
4646
* `"std"` - Enables use of the standard library.
47+
* `"approx"` - Enables approximate comparison using [`approx`].
4748

4849
These features are disabled by default:
4950

@@ -52,6 +53,7 @@ These features are disabled by default:
5253
* `"libm"` - Uses the [`libm`] floating point math library (for when the `std` feature is disabled).
5354
* `"bytemuck"` - Enables casting between plain data types using [`bytemuck`].
5455
* `"wide"` - Enables support for using SIMD types from [`wide`].
56+
* `"find-crate"` - Enables derives to find the `palette` crate when it's renamed in `Cargo.toml`.
5557

5658
### Using palette in an embedded environment
5759

@@ -353,3 +355,4 @@ at your option.
353355
[`libm`]: https://crates.io/crates/libm
354356
[`bytemuck`]: https://crates.io/crates/bytemuck
355357
[`wide`]: https://crates.io/crates/wide
358+
[`approx`]: https://crates.io/crates/approx

palette/src/alpha/alpha.rs

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use core::{
55
},
66
};
77

8+
#[cfg(feature = "approx")]
89
use approx::{AbsDiffEq, RelativeEq, UlpsEq};
910
#[cfg(feature = "random")]
1011
use rand::{
@@ -345,6 +346,7 @@ impl<C: Default, T: Stimulus> Default for Alpha<C, T> {
345346
}
346347
}
347348

349+
#[cfg(feature = "approx")]
348350
impl<C, T> AbsDiffEq for Alpha<C, T>
349351
where
350352
C: AbsDiffEq<Epsilon = T::Epsilon>,
@@ -363,6 +365,7 @@ where
363365
}
364366
}
365367

368+
#[cfg(feature = "approx")]
366369
impl<C, T> RelativeEq for Alpha<C, T>
367370
where
368371
C: RelativeEq<Epsilon = T::Epsilon>,
@@ -385,6 +388,7 @@ where
385388
}
386389
}
387390

391+
#[cfg(feature = "approx")]
388392
impl<C, T> UlpsEq for Alpha<C, T>
389393
where
390394
C: UlpsEq<Epsilon = T::Epsilon>,

palette/src/blend/pre_alpha.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use core::ops::{Add, AddAssign, Deref, DerefMut, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
22

3+
#[cfg(feature = "approx")]
34
use approx::{AbsDiffEq, RelativeEq, UlpsEq};
45

56
use crate::{
@@ -177,6 +178,7 @@ where
177178
}
178179
}
179180

181+
#[cfg(feature = "approx")]
180182
impl<C, T> AbsDiffEq for PreAlpha<C>
181183
where
182184
C: AbsDiffEq<Epsilon = T::Epsilon> + Premultiply<Scalar = T>,
@@ -195,6 +197,7 @@ where
195197
}
196198
}
197199

200+
#[cfg(feature = "approx")]
198201
impl<C, T> RelativeEq for PreAlpha<C>
199202
where
200203
C: RelativeEq<Epsilon = T::Epsilon> + Premultiply<Scalar = T>,
@@ -217,6 +220,7 @@ where
217220
}
218221
}
219222

223+
#[cfg(feature = "approx")]
220224
impl<C, T> UlpsEq for PreAlpha<C>
221225
where
222226
C: UlpsEq<Epsilon = T::Epsilon> + Premultiply<Scalar = T>,

palette/src/gradient.rs

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
use core::{cmp::max, marker::PhantomData};
77

8+
#[cfg(feature = "approx")]
89
use approx::{AbsDiffEq, RelativeEq, UlpsEq};
910

1011
use crate::{
@@ -460,6 +461,7 @@ impl<T> From<::std::ops::RangeFull> for Range<T> {
460461
}
461462
}
462463

464+
#[cfg(feature = "approx")]
463465
impl<T> AbsDiffEq for Range<T>
464466
where
465467
T: AbsDiffEq,
@@ -488,6 +490,7 @@ where
488490
}
489491
}
490492

493+
#[cfg(feature = "approx")]
491494
impl<T> RelativeEq for Range<T>
492495
where
493496
T: RelativeEq,
@@ -519,6 +522,7 @@ where
519522
}
520523
}
521524

525+
#[cfg(feature = "approx")]
522526
impl<T> UlpsEq for Range<T>
523527
where
524528
T: UlpsEq,

palette/src/hsl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use core::{
44
ops::{Add, AddAssign, BitAnd, Not, Sub, SubAssign},
55
};
66

7+
#[cfg(feature = "approx")]
78
use approx::{AbsDiffEq, RelativeEq, UlpsEq};
89
#[cfg(feature = "random")]
910
use rand::{

palette/src/hsluv.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rand::{
1212
Rng,
1313
};
1414

15+
#[cfg(feature = "approx")]
1516
use approx::{AbsDiffEq, RelativeEq, UlpsEq};
1617

1718
#[cfg(feature = "random")]

palette/src/hsv.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use core::{
44
ops::{Add, AddAssign, BitAnd, Sub, SubAssign},
55
};
66

7+
#[cfg(feature = "approx")]
78
use approx::{AbsDiffEq, RelativeEq, UlpsEq};
89
#[cfg(feature = "random")]
910
use rand::{

palette/src/hues.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
#[cfg(any(feature = "approx", feature = "random"))]
2+
use core::ops::Mul;
3+
14
use core::{
25
cmp::PartialEq,
3-
ops::{Add, AddAssign, Mul, Sub, SubAssign},
6+
ops::{Add, AddAssign, Sub, SubAssign},
47
};
58

9+
#[cfg(feature = "approx")]
610
use approx::{AbsDiffEq, RelativeEq, UlpsEq};
711

812
#[cfg(feature = "random")]
@@ -14,13 +18,13 @@ use rand::{
1418
Rng,
1519
};
1620

21+
#[cfg(feature = "approx")]
22+
use crate::{angle::HalfRotation, num::Zero};
23+
1724
#[cfg(feature = "random")]
1825
use crate::angle::FullRotation;
1926

20-
use crate::{
21-
angle::{AngleEq, FromAngle, HalfRotation, RealAngle, SignedAngle, UnsignedAngle},
22-
num::Zero,
23-
};
27+
use crate::angle::{AngleEq, FromAngle, RealAngle, SignedAngle, UnsignedAngle};
2428

2529
macro_rules! make_hues {
2630
($($(#[$doc:meta])+ struct $name:ident;)+) => ($(
@@ -185,6 +189,7 @@ macro_rules! make_hues {
185189
//
186190
// The recommendation is use 180 * epsilon as the epsilon and do not compare by
187191
// ulps. Because of this we loose some precision for values close to 0.0.
192+
#[cfg(feature = "approx")]
188193
impl<T> AbsDiffEq for $name<T>
189194
where
190195
T: RealAngle + SignedAngle + Zero + AngleEq<Mask = bool> + Sub<Output = T> + AbsDiffEq + Clone,
@@ -206,6 +211,7 @@ macro_rules! make_hues {
206211
}
207212
}
208213

214+
#[cfg(feature = "approx")]
209215
impl<T> RelativeEq for $name<T>
210216
where
211217
T: RealAngle + SignedAngle + Zero + AngleEq<Mask = bool> + Sub<Output = T> + Clone + RelativeEq,
@@ -235,6 +241,7 @@ macro_rules! make_hues {
235241
}
236242
}
237243

244+
#[cfg(feature = "approx")]
238245
impl<T> UlpsEq for $name<T>
239246
where
240247
T: RealAngle + SignedAngle + Zero + AngleEq<Mask = bool> + Sub<Output = T> + Clone + UlpsEq,

palette/src/hwb.rs

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use core::{
44
ops::{Add, AddAssign, BitAnd, DivAssign, Sub, SubAssign},
55
};
66

7+
#[cfg(feature = "approx")]
78
use approx::{AbsDiffEq, RelativeEq, UlpsEq};
89
#[cfg(feature = "random")]
910
use rand::{
@@ -576,6 +577,7 @@ impl_color_sub!(Hwb<S, T>, [hue, whiteness, blackness], standard);
576577
impl_array_casts!(Hwb<S, T>, [T; 3]);
577578
impl_simd_array_conversion_hue!(Hwb<S>, [whiteness, blackness], standard);
578579

580+
#[cfg(feature = "approx")]
579581
impl<S, T> AbsDiffEq for Hwb<S, T>
580582
where
581583
T: Stimulus + PartialOrd + Add<Output = T> + AbsDiffEq + Clone,
@@ -605,6 +607,7 @@ where
605607
}
606608
}
607609

610+
#[cfg(feature = "approx")]
608611
impl<S, T> RelativeEq for Hwb<S, T>
609612
where
610613
T: Stimulus + PartialOrd + Add<Output = T> + RelativeEq + Clone,
@@ -637,6 +640,7 @@ where
637640
}
638641
}
639642

643+
#[cfg(feature = "approx")]
640644
impl<S, T> UlpsEq for Hwb<S, T>
641645
where
642646
T: Stimulus + PartialOrd + Add<Output = T> + UlpsEq + Clone,

palette/src/lab.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use core::{
33
ops::{Add, AddAssign, BitAnd, BitOr, Div, DivAssign, Mul, MulAssign, Sub, SubAssign},
44
};
55

6+
#[cfg(feature = "approx")]
67
use approx::{AbsDiffEq, RelativeEq, UlpsEq};
78
#[cfg(feature = "random")]
89
use rand::{

palette/src/lch.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use core::{
33
ops::{Add, AddAssign, BitAnd, BitOr, Sub, SubAssign},
44
};
55

6+
#[cfg(feature = "approx")]
67
use approx::{AbsDiffEq, RelativeEq, UlpsEq};
78
#[cfg(feature = "random")]
89
use rand::{

palette/src/lchuv.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use core::{
33
ops::{Add, AddAssign, BitAnd, Mul, Sub, SubAssign},
44
};
55

6+
#[cfg(feature = "approx")]
67
use approx::{AbsDiffEq, RelativeEq, UlpsEq};
78
#[cfg(feature = "random")]
89
use rand::{

palette/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
#[cfg(any(feature = "std", test))]
206206
extern crate core;
207207

208+
#[cfg(feature = "approx")]
208209
#[cfg_attr(test, macro_use)]
209210
extern crate approx;
210211

palette/src/luma/luma.rs

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use core::{
66
ops::{Add, AddAssign, BitAnd, Div, DivAssign, Mul, MulAssign, Sub, SubAssign},
77
};
88

9+
#[cfg(feature = "approx")]
910
use approx::{AbsDiffEq, RelativeEq, UlpsEq};
1011
#[cfg(feature = "random")]
1112
use rand::{
@@ -1017,6 +1018,7 @@ impl<S> From<Lumaa<S, u8>> for u16 {
10171018

10181019
impl_simd_array_conversion!(Luma<S>, [luma], standard);
10191020

1021+
#[cfg(feature = "approx")]
10201022
impl<S, T> AbsDiffEq for Luma<S, T>
10211023
where
10221024
T: AbsDiffEq,
@@ -1032,6 +1034,7 @@ where
10321034
}
10331035
}
10341036

1037+
#[cfg(feature = "approx")]
10351038
impl<S, T> RelativeEq for Luma<S, T>
10361039
where
10371040
T: RelativeEq,
@@ -1050,6 +1053,7 @@ where
10501053
}
10511054
}
10521055

1056+
#[cfg(feature = "approx")]
10531057
impl<S, T> UlpsEq for Luma<S, T>
10541058
where
10551059
T: UlpsEq,

palette/src/luv.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use core::{
33
ops::{Add, AddAssign, BitAnd, Div, DivAssign, Mul, MulAssign, Sub, SubAssign},
44
};
55

6+
#[cfg(feature = "approx")]
67
use approx::{AbsDiffEq, RelativeEq, UlpsEq};
78
#[cfg(feature = "random")]
89
use rand::{

0 commit comments

Comments
 (0)