Crates.io | autoget |
lib.rs | autoget |
version | 0.1.2 |
source | src |
created_at | 2023-08-05 14:07:52.004283 |
updated_at | 2023-08-07 02:59:59.076756 |
description | A simple macro to generate getters for structs |
homepage | |
repository | https://github.com/zianksm/autoget |
max_upload_size | |
id | 936452 |
size | 8,880 |
A simple macro for generating getters for rust struct members.
#[derive(AutoGet)]
struct Something {
test: String,
test2: String,
test3: String,
}
this will generate code that looks something like this:
impl Something {
fn test(&self) -> &String {
&self.test
}
fn test_mut(&mut self) -> &mut String {
&mut self.test
}
fn test2(&self) -> &String {
&self.test2
}
fn test2_mut(&mut self) -> &mut String {
&mut self.test2
}
fn test3(&self) -> &String {
&self.test3
}
fn test3_mut(&mut self) -> &mut String {
&mut self.test3
}
}
to disable mutable getters you can use #[no_mut]
macro helper attributes on selected member structs.
#[derive(AutoGet)]
struct Something {
test: String,
#[no_mut]
test2: String,
test3: String,
}
or you can disable getters altogether by using #[exclude]
#[derive(AutoGet)]
struct Something {
test: String,
#[exclude]
test2: String,
test3: String,
}
you can use them alongside eachother such as:
#[derive(autoget::AutoGet)]
struct Something {
test: String,
#[exclude]
test2: String,
#[no_mut]
test3: String,
}
autoget is available under the MIT license. See the LICENSE file for more info.