eiga_builder_derive 0.3.0

A builder derive macro for the `eiga` crate
Documentation

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

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

generates

# struct Foo<'a> {
#     x: i32,
#     y: Option<&'a str>,
# }
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
    }
}