2 releases

0.1.1 Apr 11, 2023
0.1.0 Apr 11, 2023

#123 in #opinionated

Download history 806/week @ 2024-07-26 481/week @ 2024-08-02 676/week @ 2024-08-09 817/week @ 2024-08-16 865/week @ 2024-08-23 683/week @ 2024-08-30 998/week @ 2024-09-06 1148/week @ 2024-09-13 709/week @ 2024-09-20 519/week @ 2024-09-27 540/week @ 2024-10-04 1253/week @ 2024-10-11 1082/week @ 2024-10-18 1547/week @ 2024-10-25 1017/week @ 2024-11-01 1130/week @ 2024-11-08

5,114 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