These are chat archives for rust-lang/rust

20th
Nov 2016
Pavel Meledin
@btbvoy
Nov 20 2016 09:32
private type in public interface (error E0446), #[warn(private_in_public)] on by default
…
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>

If I got it correct then in upcomming releases it won’t be allowed to have reference from public structs to private? In languages like Java/Scala there is such an approach to restrict ability to initialize some class directly but using only specific builder which became public and could be used everywhere in project but creation of produced class by builder stays in the builder.

I’m trying to follow the same idea to restrict ability to init structures directly anywhere in the code but allowing to do it only in builder. With this warning from compiler and further changes which won’t allow this I’m kind of forced to make public both structs - the builder’s one and the produced struct.

Question: Is there any way to restrict ability to init structure skipping builder ?

Thomas Koehler
@Bastacyclop
Nov 20 2016 09:50
@btbvoy It won't be allowed to expose private types in public interfaces, but you can still use private types behind those interfaces:
pub struct BuilderOnly { // the type is public so you can expose it
    stuff: Stuff, // some fields are private so the user cannot initialize this struct by himself
}

pub struct Builder { ... }

impl Builder {
    // [ ... ]
    pub fn build(self) -> BuilderOnly { ... }
}
Pavel Meledin
@btbvoy
Nov 20 2016 13:07
@Bastacyclop aha. I see. That might does what I want. Thank you
Robert
@rw
Nov 20 2016 23:28
I manage an open source project that is working on adding rust support to our main library. A few months ago, we had a PR for rust support that we never merged (due to a number of issues), but the author of that PR took the blessed package name on crates.io. Is there any way for him to revoke his package, when we merge in official support for rust?
Dave Hylands
@dhylands
Nov 20 2016 23:30
@rw Not sure about that, but you can point your Crago.toml file to an arbitrary github repository. You don't have to use crates.io
Robert
@rw
Nov 20 2016 23:31
@dhylands We'd really like to get the name so that users aren't confused
Peter Atashian
@retep998
Nov 20 2016 23:50
@rw You can ask that person to add you as the owner of the crate. Then you can easily take control over it.
Robert
@rw
Nov 20 2016 23:52
@retep998 thanks!