Skip to content

Commit 0a88c18

Browse files
committed
Rename color structs to follow rust style guide
1 parent 52e12a4 commit 0a88c18

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

src/color.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn serialize_alpha(dest: &mut impl fmt::Write, alpha: f32, legacy_syntax: bool)
3434
/// A color with red, green, blue, and alpha components, in a byte each.
3535
#[derive(Clone, Copy, PartialEq, Debug)]
3636
#[repr(C)]
37-
pub struct RGBA {
37+
pub struct Rgba {
3838
/// The red component.
3939
pub red: u8,
4040
/// The green component.
@@ -45,7 +45,7 @@ pub struct RGBA {
4545
pub alpha: f32,
4646
}
4747

48-
impl RGBA {
48+
impl Rgba {
4949
/// Constructs a new RGBA value from float components. It expects the red,
5050
/// green, blue and alpha channels in that order, and all values will be
5151
/// clamped to the 0.0 ... 1.0 range.
@@ -134,7 +134,7 @@ impl RGBA {
134134
}
135135

136136
#[cfg(feature = "serde")]
137-
impl Serialize for RGBA {
137+
impl Serialize for Rgba {
138138
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
139139
where
140140
S: Serializer,
@@ -144,17 +144,17 @@ impl Serialize for RGBA {
144144
}
145145

146146
#[cfg(feature = "serde")]
147-
impl<'de> Deserialize<'de> for RGBA {
147+
impl<'de> Deserialize<'de> for Rgba {
148148
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
149149
where
150150
D: Deserializer<'de>,
151151
{
152152
let (r, g, b, a) = Deserialize::deserialize(deserializer)?;
153-
Ok(RGBA::new(r, g, b, a))
153+
Ok(Rgba::new(r, g, b, a))
154154
}
155155
}
156156

157-
impl ToCss for RGBA {
157+
impl ToCss for Rgba {
158158
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
159159
where
160160
W: fmt::Write,
@@ -180,7 +180,7 @@ impl ToCss for RGBA {
180180
/// Color specified by lightness, a- and b-axis components.
181181
#[derive(Clone, Copy, PartialEq, Debug)]
182182
#[repr(C)]
183-
pub struct LAB {
183+
pub struct Lab {
184184
/// The lightness component.
185185
pub lightness: f32,
186186
/// The a-axis component.
@@ -194,7 +194,7 @@ pub struct LAB {
194194
/// Color specified by lightness, a- and b-axis components.
195195
#[derive(Clone, Copy, PartialEq, Debug)]
196196
#[repr(C)]
197-
pub struct OKLAB {
197+
pub struct Oklab {
198198
/// The lightness component.
199199
pub lightness: f32,
200200
/// The a-axis component.
@@ -259,16 +259,16 @@ macro_rules! impl_lab_like {
259259
};
260260
}
261261

262-
impl_lab_like!(LAB, "lab");
263-
impl_lab_like!(OKLAB, "oklab");
262+
impl_lab_like!(Lab, "lab");
263+
impl_lab_like!(Oklab, "oklab");
264264

265265
// NOTE: LCH and OKLCH is not declared inside the [impl_lch_like] macro,
266266
// because it causes cbindgen to ignore them.
267267

268268
/// Color specified by lightness, chroma and hue components.
269269
#[derive(Clone, Copy, PartialEq, Debug)]
270270
#[repr(C)]
271-
pub struct LCH {
271+
pub struct Lch {
272272
/// The lightness component.
273273
pub lightness: f32,
274274
/// The chroma component.
@@ -282,7 +282,7 @@ pub struct LCH {
282282
/// Color specified by lightness, chroma and hue components.
283283
#[derive(Clone, Copy, PartialEq, Debug)]
284284
#[repr(C)]
285-
pub struct OKLCH {
285+
pub struct Oklch {
286286
/// The lightness component.
287287
pub lightness: f32,
288288
/// The chroma component.
@@ -347,29 +347,29 @@ macro_rules! impl_lch_like {
347347
};
348348
}
349349

350-
impl_lch_like!(LCH, "lch");
351-
impl_lch_like!(OKLCH, "oklch");
350+
impl_lch_like!(Lch, "lch");
351+
impl_lch_like!(Oklch, "oklch");
352352

353353
/// An absolutely specified color.
354354
/// https://w3c.github.io/csswg-drafts/css-color-4/#typedef-absolute-color-base
355355
#[derive(Clone, Copy, PartialEq, Debug)]
356356
pub enum AbsoluteColor {
357357
/// Specify sRGB colors directly by their red/green/blue/alpha chanels.
358-
RGBA(RGBA),
358+
RGBA(Rgba),
359359
/// Specifies a CIELAB color by CIE Lightness and its a- and b-axis hue
360360
/// coordinates (red/green-ness, and yellow/blue-ness) using the CIE LAB
361361
/// rectangular coordinate model.
362-
LAB(LAB),
362+
LAB(Lab),
363363
/// Specifies a CIELAB color by CIE Lightness, Chroma, and hue using the
364364
/// CIE LCH cylindrical coordinate model.
365-
LCH(LCH),
365+
LCH(Lch),
366366
/// Specifies an Oklab color by Oklab Lightness and its a- and b-axis hue
367367
/// coordinates (red/green-ness, and yellow/blue-ness) using the Oklab
368368
/// rectangular coordinate model.
369-
OKLAB(OKLAB),
369+
OKLAB(Oklab),
370370
/// Specifies an Oklab color by Oklab Lightness, Chroma, and hue using
371371
/// the OKLCH cylindrical coordinate model.
372-
OKLCH(OKLCH),
372+
OKLCH(Oklch),
373373
}
374374

375375
impl AbsoluteColor {
@@ -407,7 +407,7 @@ pub(crate) const fn rgb(red: u8, green: u8, blue: u8) -> Color {
407407

408408
#[inline]
409409
pub(crate) const fn rgba(red: u8, green: u8, blue: u8, alpha: f32) -> Color {
410-
Color::Absolute(AbsoluteColor::RGBA(RGBA::new(red, green, blue, alpha)))
410+
Color::Absolute(AbsoluteColor::RGBA(Rgba::new(red, green, blue, alpha)))
411411
}
412412

413413
/// A <color> value.
@@ -565,7 +565,7 @@ impl Color {
565565
let location = input.current_source_location();
566566
let token = input.next()?;
567567
match *token {
568-
Token::Hash(ref value) | Token::IDHash(ref value) => RGBA::parse_hash(value.as_bytes())
568+
Token::Hash(ref value) | Token::IDHash(ref value) => Rgba::parse_hash(value.as_bytes())
569569
.map(|rgba| Color::Absolute(AbsoluteColor::RGBA(rgba))),
570570
Token::Ident(ref value) => parse_color_keyword(&*value),
571571
Token::Function(ref name) => {
@@ -806,25 +806,25 @@ where
806806
// for L: 0% = 0.0, 100% = 100.0
807807
// for a and b: -100% = -125, 100% = 125
808808
"lab" => parse_lab_like(component_parser, arguments, 100.0, 125.0, |l, a, b, alpha| {
809-
Color::Absolute(AbsoluteColor::LAB(LAB::new(l.max(0.), a , b , alpha)))
809+
Color::Absolute(AbsoluteColor::LAB(Lab::new(l.max(0.), a , b , alpha)))
810810
}),
811811

812812
// for L: 0% = 0.0, 100% = 100.0
813813
// for C: 0% = 0, 100% = 150
814814
"lch" => parse_lch_like(component_parser, arguments, 100.0, 150.0, |l, c, h, alpha| {
815-
Color::Absolute(AbsoluteColor::LCH(LCH::new(l.max(0.), c.max(0.), h, alpha)))
815+
Color::Absolute(AbsoluteColor::LCH(Lch::new(l.max(0.), c.max(0.), h, alpha)))
816816
}),
817817

818818
// for L: 0% = 0.0, 100% = 1.0
819819
// for a and b: -100% = -0.4, 100% = 0.4
820820
"oklab" => parse_lab_like(component_parser, arguments, 1.0, 0.4, |l, a, b, alpha| {
821-
Color::Absolute(AbsoluteColor::OKLAB(OKLAB::new(l.max(0.), a, b, alpha)))
821+
Color::Absolute(AbsoluteColor::OKLAB(Oklab::new(l.max(0.), a, b, alpha)))
822822
}),
823823

824824
// for L: 0% = 0.0, 100% = 1.0
825825
// for C: 0% = 0.0 100% = 0.4
826826
"oklch" => parse_lch_like(component_parser, arguments, 1.0, 0.4, |l, c, h, alpha| {
827-
Color::Absolute(AbsoluteColor::OKLCH(OKLCH::new(l.max(0.), c.max(0.), h, alpha)))
827+
Color::Absolute(AbsoluteColor::OKLCH(Oklch::new(l.max(0.), c.max(0.), h, alpha)))
828828
}),
829829

830830
_ => return Err(arguments.new_unexpected_token_error(Token::Ident(name.to_owned().into()))),

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn parse_border_spacing(_context: &ParserContext, input: &mut Parser)
6969

7070
pub use crate::color::{
7171
hsl_to_rgb, hwb_to_rgb, parse_color_keyword, AbsoluteColor, AngleOrNumber, Color,
72-
ColorComponentParser, NumberOrPercentage, LAB, LCH, OKLAB, OKLCH, RGBA,
72+
ColorComponentParser, Lab, Lch, NumberOrPercentage, Oklab, Oklch, Rgba,
7373
};
7474
pub use crate::cow_rc_str::CowRcStr;
7575
pub use crate::from_bytes::{stylesheet_encoding, EncodingSupport};

src/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use super::{
1717
parse_important, parse_nth, parse_one_declaration, parse_one_rule, stylesheet_encoding,
1818
AbsoluteColor, AtRuleParser, BasicParseError, BasicParseErrorKind, Color, CowRcStr,
1919
DeclarationListParser, DeclarationParser, Delimiter, EncodingSupport, ParseError,
20-
ParseErrorKind, Parser, ParserInput, ParserState, QualifiedRuleParser, RuleListParser,
21-
SourceLocation, ToCss, Token, TokenSerializationType, UnicodeRange, RGBA,
20+
ParseErrorKind, Parser, ParserInput, ParserState, QualifiedRuleParser, Rgba, RuleListParser,
21+
SourceLocation, ToCss, Token, TokenSerializationType, UnicodeRange,
2222
};
2323

2424
macro_rules! JArray {
@@ -551,7 +551,7 @@ fn serialize_rgba() {
551551

552552
#[test]
553553
fn serialize_rgba_two_digit_float_if_roundtrips() {
554-
let c = Color::Absolute(AbsoluteColor::RGBA(RGBA::from_floats(0., 0., 0., 0.5)));
554+
let c = Color::Absolute(AbsoluteColor::RGBA(Rgba::from_floats(0., 0., 0., 0.5)));
555555
assert_eq!(c.to_css_string(), "rgba(0, 0, 0, 0.5)");
556556
}
557557

0 commit comments

Comments
 (0)