Skip to content

pantoken / platforms/rust/src / toRust

函式: toRust()

toRust(tokens, options?): string

實驗性

為明確的 token 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 const 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: … };"