Skip to content

Commit 806c2f9

Browse files
LastLeafolanod
authored andcommitted
feat: no-std for cssparser-color
1 parent 2e0e98a commit 806c2f9

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

color/Cargo.toml

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ edition = "2021"
1212
path = "lib.rs"
1313

1414
[dependencies]
15-
cssparser = { path = ".." }
16-
serde = { version = "1.0", features = ["derive"], optional = true }
15+
cssparser = { path = "..", default-features = false }
16+
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
17+
libm = "0.2.8"
1718

1819
[features]
20+
default = ["std"]
21+
std = ["cssparser/std", "serde/std"]
1922
serde = ["cssparser/serde", "dep:serde"]
2023

2124
[dev-dependencies]

color/lib.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -488,11 +488,18 @@ impl<'a> ToCss for ModernComponent<'a> {
488488
}
489489
}
490490

491+
fn f32_floor(val: f32) -> f32 {
492+
#[cfg(feature = "std")]
493+
{ val.floor() }
494+
#[cfg(not(feature = "std"))]
495+
{ libm::floorf(val) }
496+
}
497+
491498
// Guaratees hue in [0..360)
492499
fn normalize_hue(hue: f32) -> f32 {
493500
// <https://drafts.csswg.org/css-values/#angles>
494501
// Subtract an integer before rounding, to avoid some rounding errors:
495-
hue - 360.0 * (hue / 360.0).floor()
502+
hue - 360.0 * f32_floor(hue / 360.0)
496503
}
497504

498505
/// A color with red, green, blue, and alpha components, in a byte each.

0 commit comments

Comments
 (0)