Skip to content

Default values for struct fields #2936

Open
@ogoffart

Description

@ogoffart

It is often requested to have default values for struct fields

It could look like this:

struct Player {
     score: int = -1,
     name: string = "John Smith",
}

Then, when initialized, or converted from a struct with less fields, the other fields are initialized with thei default value:

component X {
   // initialized to default values
   property <Player> player1;
   // score will be -1
   property <Player> player2: { name: "Alex" };
}

The Default implementation of the rust structure or C++ default constructor must initialize the fields accordingly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:language-slintCompiler for the .slint language (mO,bF)rfcRequest for comments: proposals for changes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions