Why this fires¶
An accessor is part of a stored field's API, so it may inherit or narrow the field visibility but cannot make a private field public.
struct Account {
balance: int {
pub get // error[TE146]
}
}Allowing this would expose a member whose stored field declaration says it is private.
Fix it¶
Either remove pub from the accessor or make the field public as well:
pub balance: int {
pub get
}Use scoped visibility such as pub(mod) when the accessor should be narrower
than a public field.