Skip to main content

slint

Macro slint 

slint!() { /* proc-macro */ }
Expand description

This macro allows you to use the Slint design markup language inline in Rust code. Within the braces of the macro you can use place Slint code and the named exported components will be available for instantiation.

For the documentation about the syntax of the language, see The Slint Language Documentation

When Rust 1.88 or later is used, the paths for loading images with @image-url and importing .slint files are relative to the .rs file that contains the macro. For compatibility with older rust version, the files are also searched in the manifest directory that contains Cargo.toml.

§Limitations

Because this macro receives its input through Rust’s tokenizer, a few constructs that are valid in standalone .slint files cannot be used here:

  • String interpolation with \{...}: Rust parses the macro body as Rust string literals first, and \{...} is not a valid Rust string escape.

  • Color literals that begin with #0b (for example #0bf707): Rust’s lexer sees the 0b as the start of a numeric literal with a binary prefix, then rejects the remaining hex digits as invalid digits for that base.

  • Color literals matching #<digits>e<non-digit-hex>… (for example #10ea4c): Rust’s lexer tries to read the payload as a float with scientific notation (10e…), and rejects the non-digit characters that follow the e.

In all three cases the workarounds are to either rewrite the literal in a form Rust can tokenize (e.g. rgb(11, 247, 7) in place of #0bf707), or to move the Slint code into a .slint file and compile it via slint-build.