Uh oh!
There was an error while loading. Please reload this page.
Conversation
ghost
commented
Sep 4, 2014
Maybe I should have also mentioned that in an implementation of a trait for a concrete type, any definition for a public trait item must be marked |
huonw
commented
Sep 4, 2014
(This would be improved with some code examples.) |
Ericson2314
commented
Sep 6, 2014
Sounds good to me. I'd like to see unification of traits and modules in Rusts 2.0 or something like that, and this pushes Rust ever so slightly in that direction. |
Kimundi
commented
Sep 20, 2014
Implementing this change also allows backwards compatible removing it again in the future in case private trait items are not wanted after all: Just make the |
pnkfelix
commented
Nov 4, 2014
There was some discussion of this RFC at tonight's team meeting: discussion I think the team is generally positive about going in this direction, but there were some questions about whether putting the |
nikomatsakis
commented
Nov 5, 2014
As @pnkfelix said, the biggest sticking point was whether or not one ought to repeat the On the pro side of repeating
On the con side of repeating
Some things to consider:
Personally, I think the most likely semantics for private items in a trait would be that they can be defined anywhere but referenced only from within the module that defined the trait. I think I would prefer to do this by just denoting private things via the absence of pub, despite the possible confusion that arises, because having multiple ways to designate privacy feels like overkill -- instead people will just have to learn what privacy in an impl means. But I'm not sure about this yet. |
ghost
commented
Nov 5, 2014
For motivation, read The D Programming Language chapter 6.9.1 The Non-Virtual Interface (NVI) Idiom (by the way, we also need |
pnkfelix
commented
Nov 18, 2014
@nikomatsakis when you write "I think I would prefer to do this by just denoting private things via the absence of pub", I interpret it as a statement in support of this RFC. Is that correct, or do I misunderstand you? I am a little wary of letting the discussion here get bogged down in discussion of the details of the semantics of privacy. . . but I do agree that a small example is warranted. And by that I mean something that is both 1. not stuck behind a paywall (hint hint), and 2. written in a hypothetical extension of Rust. |
pnkfelix
commented
Nov 18, 2014
Up front caveat: I normally would not use an in-progress RFC to provide motivation for an unrelated RFC. However, @nikomatsakis and i have been talking much about this other topic recently, and so I thought he might be able to provide much insight into whether this actually could be a use case in the long term (like Rust 2.0 ... or maybe Rust 1.1 ...). @nikomatsakis also, in case you are interested: I thought that private trait items might possibly be motivated by cases I encountered while working on the placement box RFC #470. In particular, it might be possible (and desirable) to make things like the particular impl of I am thinking of something like this: pubtraitPlacer{pubtypeData;pubtypeOwner;typeInterim:PlacementAgent<Self::Data,Self::Owner>;fnmake_place(self) -> Interim;}This illustrates that the input Like so: (Of course this probably does not work in any way with today's expansion based prototype rust-lang/rust#18233 since the privacy pass is going to be looking at the expanded code.) |
ghost
commented
Nov 18, 2014
I presented this use case (for more efficient for-loops) a while ago but it turned out to be void. The general idea of it might be useful in other contexts though. The example is written assuming public by default and marking privates by |
Manishearth
commented
Nov 21, 2014
I'd personally prefer if we simply reserved (Also we may want |
glaebhoerl
commented
Nov 21, 2014
Kind of frustrating that I have a better solution (syntactically and semantically), but am mostly incapable of writing RFCs. Also that there's zero chance it would be adopted, because 1.0. (Which are not unconnected.) |
asb
commented
Nov 21, 2014
@glaebhoerl could you elaborate a little on your idea? |
aturon
commented
Nov 21, 2014
Sorry to hear that. Do you mean a solution to traits with private items? What would the backwards-incompatible changes be? |
glaebhoerl
commented
Nov 27, 2014
There's a partially written RFC here. The part specifically about closed traits is nearer the end (but builds on ideas from the earlier parts). See also the private supertraits section here, which was the genesis of this here RFC, and this earlier rejected RFC which is essentially the same idea as in the first link. The idea of closed traits just falls out as the intersection of these two ideas. The basic idea is that In each case the difference is that with the abstract/closed flavors, the type author is "hiding something" - it is an abstract type, while in the data/open case, nothing is hidden - it is "just data". In one case, fields (methods) are private by default, in the other, everything is public. Only the owner of the type may construct (via a literal) and pattern match on an abstract type, anyone may do so for data types. Built-in traits are derived automatically for data types, and must be implemented explicitly for abstract types. With an abstract type, it should not be possible for clients to observe anything that is not intentionally exposed by the author. And so on. With the analogy of See the linked RFCs for a more thorough explanation. TL;DR Existing |
aturon
commented
Mar 5, 2015
ping @pnkfelix, this seems to've fallen through the cracks? |
nikomatsakis
commented
Mar 5, 2015
I think we should close this. There doesn't seem to be momentum and it's something we can address later without breaking backwards compatibility if we so choose. |
Kimundi
commented
Mar 5, 2015
How could this be addressed later? By re-adding the |
glaebhoerl
commented
Mar 5, 2015
Or we could add (cc also @freebroccolo) |
nikomatsakis
commented
Mar 5, 2015
That is one possibility, yes. Or perhaps a modifier on the trait that makes the items private by default. -------- Original message -------- How could this be addressed later? By re-adding the priv keyword? — |
pnkfelix
commented
Mar 5, 2015
I agree we should close this. |
aturon
commented
Mar 5, 2015
OK, it seems pretty clear that nothing on this front is going to happen before 1.0, and we'll just have to use one of the suggested "workarounds" if we want to add private trait items later on. In the interest of cleaning up the RFC PRs, I'm going to go ahead and close this. Thanks for the PR! |
View