-
Notifications
You must be signed in to change notification settings - Fork 78
Allow pub attribute for struct fields #224
Copy link
Copy link
Open
Labels
Description
For struct fields, sometimes we want to control the accessibility of the fields, so they are only accessible within the struct methods.
For example:
struct Room {
pub beds: Field, // public
size: Field // private
}
Uint8.update_size(self, size: Field) {
self.size = size;
}
fn main() {
let room = Room {beds: 2, size: 10};
uint.beds = 2; // allowed
uint.size = 5; // not allowed
uint.update_size(5); // allowed
}When there is a pub attribute for a struct field, the field can be accessible from external. Otherwise, the private fields are only accessible in the struct methods.
Reactions are currently unavailable