Expand description

This crate provides a derive macro that implements the builder lite pattern.

Since this was designed to be used by eiga, it makes some assumptions:

  • The target struct has named fields.
  • Optional fields have their type written as Option<...>. The macro won’t recognize the Option type in any other form, e.g., std::option::Option.
  • Optional fields represent query string parameters.

Example

Applying #[derive(Builder)] to

#[derive(Builder)]
struct Foo<'a> {
    x: i32,
    y: Option<&'a str>,
}

generates

impl<'a> Foo<'a> {
    /// Constructs a new [`Foo`].
    pub fn new(x: i32) -> Self {
        Self {
            x,
            y: None,
        }
    }

    /// Sets the y query string parameter.
    pub fn y(mut self, y: &'a str) -> Self {
        self.y = Some(y);
        self
    }
}

Derive Macros