Skip to content

pantoken-root / platforms/rust/src / toRust

Fonction: toRust() ​

toRust(tokens, options?): string

Expérimental

Émettre des constantes Rust pour un IR de jetons explicite.

Paramètres ​

tokens ​

lecture seule Token[]

L'IR.

options? ​

RustOptions = {}

RustOptions.

Retourne ​

string

Le code source Rust (un module de pub consts).

Exemples ​

egui (Color32), le format par défaut

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), mode sombre

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: … };"