[][src]Derive Macro unprolix::Getters

#[derive(Getters)]
{
    // Attributes available to this derive:
    #[unprolix]
}

Generate pub fn attribute(&self) -> Type { &self.attribute } functions for every non-public attribute.

Skip

To skip certain attributes that you don't want to expose, you can use #[unprolix(skip)]

Copy

If your type implements Copy and references are more expensive than copying, then you can use #[unprolix(copy)]

This is recommended for raw numbers or other simple types

Slice

Its not a good practice to pass vectors as references. For that, or any type that implements an T<S, ...> fn as_slice(&self) -> &[S], you can use #[unprolix(as_slice)]

Expansion

The following code

This example is not tested
#[derive(Getters)]
struct SomeStruct {
    a: HashMap<String, i32>,
    #[unprolix(copy)]
    b: u8,
    #[unprolix(skip)]
    c: u8,
    #[unprolix(as_slice)]
    d: Vec<u8>,
}

Expands to

This example is not tested
impl SomeStruct {
    pub fn a(&self) -> &HashMap<String, i32> {
        &self.a
    }

    pub fn b(&self) -> u8 {
        self.b
    }

    pub fn d(&self) -> &[u8] {
        self.b.as_slice()
    }
}