noname
noname copied to clipboard
Allow pub attribute for struct fields
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.
I guess the example should have Uint8 replaced with Room and uint with room right?
I can try to attempt this if no one else is already working on it.
yes, and sg!