https://github.com/andrewgazelka/derive-build
🦀 An opinionated builder macro in Rust
https://github.com/andrewgazelka/derive-build
proc-macro proc-macro-derive rust
Last synced: 9 months ago
JSON representation
🦀 An opinionated builder macro in Rust
- Host: GitHub
- URL: https://github.com/andrewgazelka/derive-build
- Owner: andrewgazelka
- Created: 2023-04-11T15:35:34.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-11T17:35:21.000Z (about 3 years ago)
- Last Synced: 2025-04-06T04:03:03.807Z (about 1 year ago)
- Topics: proc-macro, proc-macro-derive, rust
- Language: Rust
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# derive-build
[](http://crates.io/crates/derive-build)
An opinionated builder macro in Rust
```rust
#[derive(Default, Build, Eq, PartialEq, Debug)]
struct Request {
#[required]
url: String,
path: Option,
messages: Vec,
}
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
- [x] Required fields
- [x] Optional fields
- [x] Default values for optional fields
- [ ] Default values for required fields (instead make option)
- [x] Support for `Option` fields
- [x] Support for `Vec` fields
- [x] Support for `Cow<'a, T>` fields
- [x] Support for references (`&'a T`) fields
- [x] Automatic `Into` conversions
- [x] Automatic singularization of field names
- [x] Support for `HashMap` fields
- [x] Support for `HashSet` fields
- [x] Support for `BTreeMap` fields
- [x] Support for `BTreeSet` fields
- [x] Support for `Box` fields
- [x] Support for `Rc` fields
- [x] Support for `Arc` fields
- [x] Support for integer types