derive-build

Crates.ioderive-build
lib.rsderive-build
version0.1.1
sourcesrc
created_at2023-04-11 15:43:17.09987
updated_at2023-04-11 17:25:21.904594
descriptionAn opinionated builder macro in Rust
homepage
repositoryhttps://github.com/andrewgazelka/derive-build
max_upload_size
id836136
size18,951
Andrew Gazelka (andrewgazelka)

documentation

README

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
Commit count: 14

cargo fmt