Crate derive_getters[][src]

Derive Getters

Macro for autogenerating getters. Can only be used on named structs. Will generate getters that will reside in the struct namespace through an impl. If the struct already has a method defined with the same name as one of the fields, this crate will barrel on and you'll end up with a duplicate method name.


Add to your project Cargo.toml;

derive-getters = "0.0.7"

In or;

extern crate derive_getters;


extern crate derive_getters;

struct Number {
   num: u64,    
fn main() {
   let number = Number { num: 655 };
   assert!(number.num() == &655);

Here, a method called num() has been created for the Number struct which gives a reference to the num field.



Derive getters into a seperate trait for the named struct.