2 releases

0.1.1 Apr 11, 2023
0.1.0 Apr 11, 2023

#78 in #required

Download history 849/week @ 2024-04-03 757/week @ 2024-04-10 588/week @ 2024-04-17 455/week @ 2024-04-24 444/week @ 2024-05-01 498/week @ 2024-05-08 469/week @ 2024-05-15 538/week @ 2024-05-22 443/week @ 2024-05-29 483/week @ 2024-06-05 591/week @ 2024-06-12 470/week @ 2024-06-19 588/week @ 2024-06-26 526/week @ 2024-07-03 411/week @ 2024-07-10 704/week @ 2024-07-17

2,312 downloads per month
Used in 3 crates (via tokio-openai)

MIT license

11KB
185 lines

derive-build

Crates.io

An opinionated builder macro in Rust

#[derive(Default, Build, Eq, PartialEq, Debug)]
struct Request {
    #[required]
    url: String,

    path: Option<String>,

    messages: Vec<String>,
}

fn main() {
    let request = Request::new("example.com")
        .path("tester")
        .message("hello")
        .message("goodbye");

    let expected = Request {
        url: "example.com".to_string(),
        path: Some("tester".to_string()),
        messages: vec!["hello".to_string(), "goodbye".to_string()],
    };

    assert_eq!(request, expected);
}

Features

  • Required fields
  • Optional fields
  • Default values for optional fields
  • Default values for required fields (instead make option)
  • Support for Option<T> fields
  • Support for Vec<T> fields
  • Support for Cow<'a, T> fields
  • Support for references (&'a T) fields
  • Automatic Into<T> conversions
  • Automatic singularization of field names
  • Support for HashMap<K, V> fields
  • Support for HashSet<T> fields
  • Support for BTreeMap<K, V> fields
  • Support for BTreeSet<T> fields
  • Support for Box<T> fields
  • Support for Rc<T> fields
  • Support for Arc<T> fields
  • Support for integer types

Dependencies

~0.4–0.9MB
~19K SLoC