Tech
Intermediary between public and private members
Say I were to have a
struct Foo { pub public: Bar, restricted: Qux }
where ‘restricted’ is some member variable which I want to be able to get, but not set, from outside of the struct methods. Normally, I would write a getter method
impl Foo { pub fn restricted(&self) -> &Qux { self.restricted }}
which isn’t very much typing, and probably I could generate these automatically with an IDE or a plugin.
But all the same, why not build this into the declaration syntax with a ...
Read the full discussion on Lobsters
This article was aggregated from Lobsters. Click to join the conversation.
View on Lobsters