-
Notifications
You must be signed in to change notification settings - Fork 228
Description
Greetings, I was recently reading the comments on a proposal I made, which discusses implicit constructors, and the idea came to me because the Dart language doesn't have the typical structures that use the reserved word struct and implicit constructors. What better way to explain something than by showing a code example to provide better context:
This is an example of what a basic structure would look like.
struct User {
active: bool,
username: String,
email: String,
}
void main() {
final myUser = User(true, "maria", "[email protected]");
print(myUser.username); //print: maria
}This is an example of how to instantiate a structure using dot shorthands.
struct User {
active: bool,
username: String,
email: String,
}
void main() {
final User myUser = .new(true, "maria", "[email protected]");
print(myUser.username); //print: maria
}The purpose of having structs in the Dart language is to give meaning to classes that only carry data, acting as a specific abstraction for that particular use case. You can read more about what structs are in the official Rust documentation.
The structures give meaning to the code and allow for simplified interoperability with low-level languages such as Rust and C++.