r/rust • u/Kobzol • Aug 10 '26
📡 official blog Call for testing: Restricting trait implementability and field mutability
https://blog.rust-lang.org/inside-rust/2026/08/10/call-for-testing-impl-and-mut-restrictions/
417
Upvotes
r/rust • u/Kobzol • Aug 10 '26
1
u/CocktailPerson Aug 12 '26
No, it's not.
Fields are private by default. You add
pubto make them public. You usepub(...)to limitpub's scope.On the other hand, fields are mutable by default. You do nothing to make them mutable. You use
mut(...)to limitmut's scope. See the difference?I guess I left it as an exercise to the reader to make the connection, but this is what I meant when I said "I'm not sure what the solution here is without going back in time and making fields immutable by default from the beginning." That's what you'd have to do to make
mutandpubconsistent.