field-visibility

Crates.iofield-visibility
lib.rsfield-visibility
version0.1.0
sourcesrc
created_at2024-09-01 13:30:13.503632
updated_at2024-09-01 13:30:13.503632
descriptionAttribute to specify the visibility of all fields in a Rust struct
homepagehttps://github.com/zfzackfrost/field-visibility
repositoryhttps://github.com/zfzackfrost/field-visibility
max_upload_size
id1359629
size4,730
Zachary Frost (zfzackfrost)

documentation

README

field-visibility

Attribute to specify the visibility of all fields in a Rust struct.

Usage

Examples

The argument is the visibility mode (i.e. pub or pub(crate)).

To set all fields in the struct to public:

use field_visibility::visibility;

#[visibility(pub)] // Or `pub(crate)`, etc.
struct Widget {
    a: i32,
    b: i32,
}

This expands to:

use field_visibility::visibility;

#[visibility(pub)]
struct Widget {
    pub a: i32,
    pub b: i32,
}

When using this attribute, the visibility of individual fields can be set.

use field_visibility::visibility;

#[visibility(pub)]
struct SomeStruct {
    field1: i32,
    field2: i32,

    pub(crate) crate_field: i32,

    pub(self) private_field: i32, // Equivalent to private
}

The expansion of this is:

struct SomeStruct {
    pub field1: i32,
    pub field1: i32,

    pub(crate) crate_field: i32,

    pub(self) private_field: i32,
}
Commit count: 0

cargo fmt