Skip to content

#[derive(new)] on non-pub struct should give fn new the right visibility (required for 2018 idioms) #40

@wycats

Description

@wycats

Today, #[derive(new)] always creates a pub 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:

#[derive(new)]
#[new(visibility = crate)]
struct Point {
    x: u32,
    y: u32,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions