Initial release of shorthand, a library for deriving useful getter and setter

I just released a new crate called shorthand, which makes writing libraries a lot faster (development time).

What does this library do?

It makes writing code in rust a lot more convenient. Library authors often do not want to make the internal fields public and therefore expose functions to get and set the value of the field.

Without shorthand you would have to write all this code:

pub struct Example {
    number: usize,
    data: String,
}

#[allow(dead_code)]
impl Example {
    #[inline(always)]
    pub fn number(&self) -> usize { self.number }

    #[inline(always)]
    pub fn set_number(&mut self, value: usize) -> &mut Self {
        self.number = value;
        self
    }

    #[inline(always)]
    pub fn data(&self) -> &String { &self.data }

    #[inline(always)]
    pub fn set_data(&mut self, value: String) -> &mut Self {
        self.data = value;
        self
    }
}

My library makes this a lot more convenient:

use shorthand::ShortHand;

#[derive(ShortHand)]
pub struct Example {
    number: usize,
    data: String,
}

This is my first proc_macro, so some suggestions would be appreciated :slight_smile:

Yeah I know, that the attribute parsing code is horrible, but I do not know how to improve it anymore.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.