Skip to content

Structs and Enums

Define named structures using the struct keyword:

export struct Player {
name: string,
score: int,
}
export component Example {
in-out property<Player> player: { name: "Foo", score: 100 };
}
slint

The default value of a struct, is initialized with all its fields set to their default value.

Declare a default value for a field with = expression after its type. The expression must be a compile-time constant. The default applies whenever an instance of the struct is created without a value for the field: in struct literals that omit the field, for properties that are never set, and when constructing the struct from Rust (Player::default()), C++ (Player{}), JavaScript (new ui.Player()), or Python (ui.Player()).

export struct Player {
name: string = "unknown",
score: int = 100,
}
export component Example {
// player.name is "Foo", player.score is 100
in-out property<Player> player: { name: "Foo" };
}
slint

Declare anonymous structures using { identifier1: type1, identifier2: type2 } syntax, and initialize them using { identifier1: expression1, identifier2: expression2 }.

You may have a trailing , after the last expression or type.

export component Example {
in-out property<{name: string, score: int}> player: { name: "Foo", score: 100 };
in-out property<{a: int, }> foo: { a: 3 };
}
slint

Define an enumeration with the enum keyword:

export enum CardSuit { clubs, diamonds, hearts, spade }
export component Example {
in-out property<CardSuit> card: spade;
out property<bool> is-clubs: card == CardSuit.clubs;
}
slint

Enum values can be referenced by using the name of the enum and the name of the value separated by a dot. (eg: CardSuit.spade)

The name of the enum can be omitted wherever a value of that enum type is expected, such as in a binding, a struct field, an array element, a function or callback argument, or a return value:

export enum CardSuit { clubs, diamonds, hearts, spade }
export struct Card { suit: CardSuit, value: int }
export component Example {
// in a struct field and an array element
out property<Card> card: { suit: hearts, value: 10 };
out property<[CardSuit]> deck: [clubs, diamonds, hearts, spade];
pure function is-red(suit: CardSuit) -> bool {
return suit == hearts || suit == diamonds;
}
// as a function argument
out property<bool> spade-is-red: is-red(spade);
}
slint

In a comparison the name can be omitted only on the right-hand side, which takes the type of the left: card.suit == hearts works, but hearts == card.suit does not.

The default value of each enum type is always the first value.


© 2026 SixtyFPS GmbH