A set of derive macros to automatically generate getters/setters. This is a educational project and is not optimized in any way (for now at least)
Add this to your Cargo.toml:
[dependencies]
access-derive = "^0.1"access-derive comes with a set of field attributes that generates automatically getters and setters.
Consider a simple structure as follow:
pub struct MyStruct {
foo: String,
}Attributes added to the foo field will have following effects:
#[access(get)]will produce a methodfoo(&self) -> &String { ... }#[access(get(ref = "&str"))]will produce a methodfoo(&self) -> &str { ... }#[access(get(ref_mut)]will produce a methodfoo(&self) -> &mut String { ... }#[access(set)]will produce a methodset_foo(&mut self, String) { ... }
If I have the time/will, here's a list of things that I am not happy about
- Errors reported are a bit wierd, due to spans when generating methods
-
setattribute should take an argument to specify a custom type -
setattribute should take aref