On 13-04-17 02:26 PM, Graydon Hoare wrote:
On 17/04/2013 11:58 AM, Brandon Mintern wrote:
Please let's not get derailed here. I wasn't bemoaning the difficulty of
implementing list iterators. I was trying to offer a simple example
everyone could understand to show when protected might be useful. There
are definitely times when implementing an interface that it's more
convenient or efficient to use an object's non-public API.

This discussion is not about list iterators, it's about whether it makes
sense to have any visibility other than public and private. I argued
that protected doesn't buy much over using unsafe private.

Yes. Our concept of visibility is a fair bit different from the way it
works in other OO languages. Rust's visibility modifiers control whether
one bit of code can see across a module boundary, no more.

Fields of a struct are always visible to anyone who can see the struct
definition.

Ah, of course, this is wrong; I forget people do sometimes set per-field visibility and it refines the concept of type visibility. I never use the per-field part.

I guess all I was getting at is that pub and priv currently only relate to the module structure, not the impl structure. I think! And I think that makes them cognitively pretty straightforward, so I am generally against trying to entangle them with other concepts. You can see priv definitions when you're inside a module with it, otherwise not. That's an easy rule to explain and it seems to compose well given how powerful the module system is.

(Moreover, I think the proposed form of "protected" would not really buy much protection anyway, since you could always make up a trait and implement it if you wanted access to such a field.)

-Graydon

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to