Skip to content

Commit

Permalink
Remove the "cam16" Cargo feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Ogeon committed Mar 31, 2024
1 parent 33b9f4f commit ca34a3a
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 100 deletions.
2 changes: 1 addition & 1 deletion no_std_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bench = false
[features]
nightly = []
# Avoids getting these features included in other packages in the same workspace.
all_features = ["palette/libm", "palette/named_from_str", "palette/cam16"]
all_features = ["palette/libm", "palette/named_from_str"]

[dependencies.libc]
version = "0.2"
Expand Down
1 change: 0 additions & 1 deletion palette/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ rust-version = "1.60.0"

[features]
default = ["named_from_str", "std", "approx"]
cam16 = ["palette_derive/cam16"]
named_from_str = ["named", "phf"]
named = []
random = ["rand"]
Expand Down
4 changes: 0 additions & 4 deletions palette/src/hues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,10 +799,7 @@ make_hues! {
///
/// It's measured in degrees.
struct OklabHue; OklabHueIter
}

#[cfg(feature = "cam16")]
make_hues! {
/// A hue type for the CAM16 color appearance model.
///
/// It's measured in degrees.
Expand Down Expand Up @@ -902,7 +899,6 @@ impl_uniform!(UniformLabHue, LabHue);
impl_uniform!(UniformRgbHue, RgbHue);
impl_uniform!(UniformLuvHue, LuvHue);
impl_uniform!(UniformOklabHue, OklabHue);
#[cfg(feature = "cam16")]
impl_uniform!(UniformCam16Hue, Cam16Hue);

#[cfg(test)]
Expand Down
1 change: 0 additions & 1 deletion palette/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ pub mod alpha;
pub mod angle;
pub mod blend;
pub mod bool_mask;
#[cfg(feature = "cam16")]
pub mod cam16;
pub mod cast;
pub mod chromatic_adaptation;
Expand Down
3 changes: 0 additions & 3 deletions palette_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,3 @@ syn = { version = "2.0.13", default-features = false, features = [
quote = "^1.0"
proc-macro2 = "^1.0"
find-crate = { version = "0.6", optional = true }

[features]
cam16 = []
62 changes: 0 additions & 62 deletions palette_derive/src/color_types.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,20 @@
pub(crate) struct ColorGroup {
pub(crate) root_type: ColorInfo,
pub(crate) cargo_feature: Option<CargoFeature>,
pub(crate) colors: &'static [ColorType],
}

pub(crate) struct ColorType {
pub(crate) info: ColorInfo,
pub(crate) preferred_source: &'static str,
pub(crate) cargo_feature: Option<CargoFeature>,
}

pub(crate) struct ColorInfo {
pub(crate) name: &'static str,
}

pub(crate) struct CargoFeature {
name: &'static str,
enabled: bool,
}

macro_rules! cargo_feature {
($name: literal) => {
CargoFeature {
name: $name,
enabled: cfg!(feature = $name),
}
};
}

impl ColorGroup {
pub(crate) fn check_availability(&self, name: &str) -> Result<(), ColorError> {
if name == self.root_type.name {
if let Some(CargoFeature {
name: feature,
enabled: false,
}) = self.cargo_feature
{
return Err(ColorError::RequiresFeature(feature));
}

return Ok(());
}

Expand All @@ -47,22 +23,6 @@ impl ColorGroup {
continue;
}

if let Some(CargoFeature {
name: feature,
enabled: false,
}) = self.cargo_feature
{
return Err(ColorError::RequiresFeature(feature));
}

if let Some(CargoFeature {
name: feature,
enabled: false,
}) = color.cargo_feature
{
return Err(ColorError::RequiresFeature(feature));
}

return Ok(());
}

Expand Down Expand Up @@ -96,115 +56,94 @@ impl Iterator for ColorNames {

const BASE_COLORS: ColorGroup = ColorGroup {
root_type: ColorInfo { name: "Xyz" },
cargo_feature: None,
colors: &[
ColorType {
info: ColorInfo { name: "Rgb" },
preferred_source: "Xyz",
cargo_feature: None,
},
ColorType {
info: ColorInfo { name: "Luma" },
preferred_source: "Xyz",
cargo_feature: None,
},
ColorType {
info: ColorInfo { name: "Hsl" },
preferred_source: "Rgb",
cargo_feature: None,
},
ColorType {
info: ColorInfo { name: "Hsluv" },
preferred_source: "Lchuv",
cargo_feature: None,
},
ColorType {
info: ColorInfo { name: "Hsv" },
preferred_source: "Rgb",
cargo_feature: None,
},
ColorType {
info: ColorInfo { name: "Hwb" },
preferred_source: "Hsv",
cargo_feature: None,
},
ColorType {
info: ColorInfo { name: "Lab" },
preferred_source: "Xyz",
cargo_feature: None,
},
ColorType {
info: ColorInfo { name: "Lch" },
preferred_source: "Lab",
cargo_feature: None,
},
ColorType {
info: ColorInfo { name: "Lchuv" },
preferred_source: "Luv",
cargo_feature: None,
},
ColorType {
info: ColorInfo { name: "Luv" },
preferred_source: "Xyz",
cargo_feature: None,
},
ColorType {
info: ColorInfo { name: "Oklab" },
preferred_source: "Xyz",
cargo_feature: None,
},
ColorType {
info: ColorInfo { name: "Oklch" },
preferred_source: "Oklab",
cargo_feature: None,
},
ColorType {
info: ColorInfo { name: "Okhsl" },
preferred_source: "Oklab",
cargo_feature: None,
},
ColorType {
info: ColorInfo { name: "Okhsv" },
preferred_source: "Oklab",
cargo_feature: None,
},
ColorType {
info: ColorInfo { name: "Okhwb" },
preferred_source: "Okhsv",
cargo_feature: None,
},
ColorType {
info: ColorInfo { name: "Yxy" },
preferred_source: "Xyz",
cargo_feature: None,
},
],
};

const CAM16_COLORS: ColorGroup = ColorGroup {
root_type: ColorInfo { name: "Cam16" },
cargo_feature: Some(cargo_feature!("cam16")),
colors: &[
ColorType {
info: ColorInfo {
name: "PartialCam16",
},
preferred_source: "Cam16",
cargo_feature: None,
},
ColorType {
info: ColorInfo {
name: "Cam16UcsJmh",
},
preferred_source: "PartialCam16",
cargo_feature: None,
},
ColorType {
info: ColorInfo {
name: "Cam16UcsJab",
},
preferred_source: "Cam16UcsJmh",
cargo_feature: None,
},
],
};
Expand Down Expand Up @@ -232,5 +171,4 @@ impl Default for AvailableColorGroup {

pub(crate) enum ColorError {
UnknownColor,
RequiresFeature(&'static str),
}
6 changes: 3 additions & 3 deletions palette_derive/src/convert/from_color_unclamped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ fn prepare_from_impl_for_pair(
}
};

// Skip implementing the trait where it wouldn't be able to constrain
// the white point. This is only happening when certain optional
// features, such as "cam16", are enabled.
// Skip implementing the trait where it wouldn't be able to constrain the
// white point. This is only happening when certain optional features are
// enabled.
if used_input.white_point.is_unconstrained()
&& matches!(white_point_source, WhitePointSource::GeneratedGeneric)
{
Expand Down
25 changes: 0 additions & 25 deletions palette_derive/src/meta/type_item_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ impl AttributeArgumentParser for TypeItemAttributes {
skipped_color.span(),
format!("`{}` is not a valid color type", skipped_color),
)),
Err(ColorError::RequiresFeature(feature)) => {
errors.push(syn::Error::new(
skipped_color.span(),
format!(
"`{}` is only usable with the `{}` feature",
skipped_color, feature
),
))
}
}
}

Expand All @@ -81,28 +72,12 @@ impl AttributeArgumentParser for TypeItemAttributes {
Some("luma_standard") => {
get_meta_type_argument(argument, &mut self.luma_standard)?;
}
#[cfg(feature = "cam16")]
Some("cam16_chromaticity") => {
get_meta_type_argument(argument, &mut self.cam16_chromaticity)?;
}
#[cfg(not(feature = "cam16"))]
Some("cam16_chromaticity") => {
return Err(vec![syn::Error::new(
argument.span(),
"`cam16_chromaticity` is only usable with the `cam16` feature",
)]);
}
#[cfg(feature = "cam16")]
Some("cam16_luminance") => {
get_meta_type_argument(argument, &mut self.cam16_luminance)?;
}
#[cfg(not(feature = "cam16"))]
Some("cam16_luminance") => {
return Err(vec![syn::Error::new(
argument.span(),
"`cam16_luminance` is only usable with the `cam16` feature",
)]);
}
Some("color_group") => {
let mut errors = Vec::new();

Expand Down

0 comments on commit ca34a3a

Please sign in to comment.