2 releases
0.1.1 | Apr 11, 2023 |
---|---|
0.1.0 | Apr 11, 2023 |
#78 in #required
2,312 downloads per month
Used in 3 crates
(via tokio-openai)
11KB
185 lines
derive-build
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