Open wycats opened 6 years ago
Yes, please allow making new
private even for public structs/enums.
In several of my use cases I only intend to call the derived new
internally, and I get this error:
error: private type in public interface. can't leak private type
Because the derived new
takes as arg a private type, to initialize a private member.
I've run into this, and now (since this is a relatively recent Rust feature) with wanting a const fn new
.
I still think this is a good idea, even though the original annoying issue is no longer the root cause of the problem.
Today,
#[derive(new)]
always creates apub fn
, regardless of the visibility of the struct it's applied to.In Rust 2018, that becomes a lint error, which makes it (at present) difficult to use this crate in a crate with
#[warn(rust_2018_idioms)]
.Instead, the visibility of the
new
method should be the same as the visibility of the struct.It might also be useful to allow the visibility to be controlled directly. Straw man: