Skip to content

pantoken-root / platforms/rust/src / toRust

函数: toRust() ​

toRust(tokens, options?): string

实验性

为显式的令牌 IR 生成 Rust 常量。

参数 ​

tokens ​

只读 Token[]

IR。

options? ​

RustOptions = {}

RustOptions.

返回值 ​

string

Rust 源代码(一个由 pub consts 组成的模块)。

示例 ​

egui(Color32),默认格式

ts
import { toRust } from "@pantoken/rust";
import { byTheme } from "@pantoken/tokens";

const source = toRust(byTheme("rebrand"));
// "use egui::Color32;\npub fn color_background_brand() -> Color32 { Color32::from_rgb(…) }"

iced(Color),暗色模式

ts
import { toRust } from "@pantoken/rust";
import { byTheme } from "@pantoken/tokens";

const source = toRust(byTheme("rebrand"), { format: "iced", mode: "dark" });
// "use iced::Color;\npub const COLOR_BACKGROUND_BRAND: Color = Color { r: …, g: …, b: …, a: … };"