Allow compiling with Rust code (#3137)

Co-authored-by: Yuri Astrakhan <YuriAstrakhan@gmail.com>
Co-authored-by: Ian Wagner <ianwagner+github@switzerlandmail.ch>
This commit is contained in:
Bart Louwers
2025-01-16 16:01:11 +01:00
committed by GitHub
parent 79d625b03c
commit 527e70b6fa
23 changed files with 649 additions and 25 deletions

35
rustutils/src/color.rs Normal file
View File

@@ -0,0 +1,35 @@
use csscolorparser::Color;
#[cxx::bridge(namespace = "rustutils")]
mod ffi {
struct ParsedColor {
pub success: bool,
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}
extern "Rust" {
fn parse_css_color(css_str: &str) -> ParsedColor;
}
}
pub fn parse_css_color(css_str: &str) -> ffi::ParsedColor {
css_str
.parse::<Color>()
.map(|color| ffi::ParsedColor {
success: true,
r: color.r as f32,
g: color.g as f32,
b: color.b as f32,
a: color.a as f32,
})
.unwrap_or_else(|_| ffi::ParsedColor {
success: false,
r: 0.0,
g: 0.0,
b: 0.0,
a: 0.0,
})
}

1
rustutils/src/lib.rs Normal file
View File

@@ -0,0 +1 @@
mod color;