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.
Usage
Add to your project Cargo.toml;
[dependencies]
derive-getters = "0.0.7"
In lib.rs or main.rs;
#[macro_use] extern crate derive_getters;
Example
#[macro_use] extern crate derive_getters; #[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.
Functions
getters |
Derive getters into a seperate trait for the named struct. |