Crates.io | field-visibility |
lib.rs | field-visibility |
version | 0.1.0 |
source | src |
created_at | 2024-09-01 13:30:13.503632 |
updated_at | 2024-09-01 13:30:13.503632 |
description | Attribute to specify the visibility of all fields in a Rust struct |
homepage | https://github.com/zfzackfrost/field-visibility |
repository | https://github.com/zfzackfrost/field-visibility |
max_upload_size | |
id | 1359629 |
size | 4,730 |
Attribute to specify the visibility of all fields in a Rust struct
.
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,
}