Saltar al contenido
← volver

Intermediary between public and private members

Lobste.rs · lobste.rs Publicado:

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 modifier in between priv…

Leer original →Comentarios en la fuente

Más de Lobste.rs