-
-
Notifications
You must be signed in to change notification settings - Fork 197
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Is your feature request related to a problem? Please describe.
I'd like an ability to set a default value for struct fields. This is particularly useful for structs that are mixed into other structs, where you have to retroactively update multiple struct initializers or constructors to properly initialize the new mixed-in field.
Describe the solution you'd like
struct MyStruct {
can_drop: bool = true;
}
struct MyStruct2 {
use MyStruct;
val: int;
}
impl MyStruct2 {
fn new() -> Self {
// Initializes can_drop to true because it's omitted
return MyStruct2{ val: 10 };
}
}Describe alternatives you've considered
- Manually initializing the field in every struct that uses the mixin and retroactively updating their initializers to include new fields added later.
- Adding function
init_my_struct(s: MyStruct*) { s.can_drop = true; }to call every time.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request