This commit is contained in:
Sam Johnson 2023-07-05 09:59:06 -04:00
parent 2054845649
commit 5b8b1366e3
No known key found for this signature in database
GPG key ID: B0C7B1CDE21F404B
2 changed files with 38 additions and 0 deletions

19
README.md Normal file
View file

@ -0,0 +1,19 @@
A simple attribute that makes all fields public on a struct.
Usage:
```rust
#[pub_fields]
pub struct MyStruct {
a: usize,
b: usize,
c: usize,
}
```
=>
```rust
pub struct MyStruct {
pub a: usize,
pub b: usize,
pub c: usize,
}
```

View file

@ -2,6 +2,25 @@ use proc_macro::TokenStream;
use quote::ToTokens;
use syn::{parse::Nothing, parse_macro_input, parse_quote, ItemStruct};
/// A simple attribute that makes all fields public on a struct.
///
/// Usage:
/// ```rust
/// #[pub_fields]
/// pub struct MyStruct {
/// a: usize,
/// b: usize,
/// c: usize,
/// }
/// ```
/// =>
/// ```rust
/// pub struct MyStruct {
/// pub a: usize,
/// pub b: usize,
/// pub c: usize,
/// }
/// ```
#[proc_macro_attribute]
pub fn pub_fields(attr: TokenStream, tokens: TokenStream) -> TokenStream {
parse_macro_input!(attr as Nothing);