{"id":13648614,"url":"https://github.com/idanarye/rust-typed-builder","last_synced_at":"2025-05-13T16:07:09.208Z","repository":{"id":39580279,"uuid":"105786399","full_name":"idanarye/rust-typed-builder","owner":"idanarye","description":"Compile-time type-checked builder derive","archived":false,"fork":false,"pushed_at":"2025-03-20T12:52:04.000Z","size":398,"stargazers_count":1012,"open_issues_count":36,"forks_count":57,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-03T03:09:38.154Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://crates.io/crates/typed-builder","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/idanarye.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-10-04T15:41:10.000Z","updated_at":"2025-05-02T04:44:14.000Z","dependencies_parsed_at":"2023-02-15T23:31:06.590Z","dependency_job_id":"be12363f-84ab-44eb-ac18-63f823b33190","html_url":"https://github.com/idanarye/rust-typed-builder","commit_stats":{"total_commits":276,"total_committers":34,"mean_commits":8.117647058823529,"dds":0.6884057971014492,"last_synced_commit":"97edb3fa740f60cf519f690e07fb2a4afa17d54f"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idanarye%2Frust-typed-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idanarye%2Frust-typed-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idanarye%2Frust-typed-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idanarye%2Frust-typed-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/idanarye","download_url":"https://codeload.github.com/idanarye/rust-typed-builder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253979991,"owners_count":21994041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T01:04:23.612Z","updated_at":"2025-05-13T16:07:09.188Z","avatar_url":"https://github.com/idanarye.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"[![Build Status](https://github.com/idanarye/rust-typed-builder/workflows/CI/badge.svg)](https://github.com/idanarye/rust-typed-builder/actions)\n[![Latest Version](https://img.shields.io/crates/v/typed-builder.svg)](https://crates.io/crates/typed-builder)\n[![Rust Documentation](https://img.shields.io/badge/api-rustdoc-blue.svg)](https://idanarye.github.io/rust-typed-builder/)\n\n# Rust Typed Builder\n\nCreates a compile-time verified builder:\n\n```rust\nuse typed_builder::TypedBuilder;\n\n#[derive(TypedBuilder)]\nstruct Foo {\n    // Mandatory Field:\n    x: i32,\n\n    // #[builder(default)] without parameter - use the type's default\n    // #[builder(setter(strip_option))] - wrap the setter argument with `Some(...)`\n    #[builder(default, setter(strip_option))]\n    y: Option\u003ci32\u003e,\n\n    // Or you can set the default\n    #[builder(default=20)]\n    z: i32,\n}\n```\n\nBuild in any order:\n```rust\nFoo::builder().x(1).y(2).z(3).build();\nFoo::builder().z(1).x(2).y(3).build();\n```\n\nOmit optional fields(the one marked with `#[default]`):\n```rust\nFoo::builder().x(1).build()\n```\n\nBut you can't omit non-optional arguments - or it won't compile:\n```rust\nFoo::builder().build(); // missing x\nFoo::builder().x(1).y(2).y(3); // y is specified twice\n```\n\n## Features\n\n* Custom derive for generating the builder pattern.\n* Ability to annotate fields with `#[builder(setter(into))]` to make their setters accept `Into` values.\n* Compile time verification that all fields are set before calling `.build()`.\n* Compile time verification that no field is set more than once.\n* Ability to annotate fields with `#[builder(default)]` to make them optional and specify a default value when the user does not set them.\n* Generates simple documentation for the `.builder()` method.\n* Customizable method name and visibility of the `.build()` method.\n\n## Limitations\n\n* The build errors when you neglect to set a field or set a field describe the actual problem as a deprecation warning, not as the main error.\n* The generated builder type has ugly internal name and many generic parameters. It is not meant for passing around and doing fancy builder tricks - only for nicer object creation syntax(constructor with named arguments and optional arguments).\n    * For the that reason, all builder methods are call-by-move and the builder is not cloneable. Saves the trouble of determining if the fields are cloneable...\n    * If you want a builder you can pass around, check out [derive-builder](https://crates.io/crates/derive_builder). It's API does not conflict with typed-builder's so you can be able to implement them both on the same type.\n\n## Conflicts\n\n* `TypedBuilder` accepts arbitrary Rust code for `#[builder(default = ...)]`, but other custom derive proc-macro crates may try to parse them using the older restrictions that allow only literals. To solve this, use `#[builder(default_code = \"...\")]` instead.\n\n## Alternatives - and why typed-builder is better\n\n* [derive-builder](https://crates.io/crates/derive_builder) - does all the checks in runtime, returning a `Result` you need to unwrap.\n* [safe-builder-derive](https://crates.io/crates/safe-builder-derive) - this one does compile-time checks - by generating a type for each possible state of the builder. Rust can remove the dead code, but your build time will still be exponential. typed-builder is encoding the builder's state in the generics arguments - so Rust will only generate the path you actually use.\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any\nadditional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidanarye%2Frust-typed-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidanarye%2Frust-typed-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidanarye%2Frust-typed-builder/lists"}