typed-builder-0.20.0/.cargo_vcs_info.json 0000644 00000000136 00000000001 0013664 0 ustar {
"git": {
"sha1": "97edb3fa740f60cf519f690e07fb2a4afa17d54f"
},
"path_in_vcs": ""
} typed-builder-0.20.0/.github/dependabot.yml 0000644 0000000 0000000 00000000362 10461020230 0016645 0 ustar 0000000 0000000 version: 2
updates:
- package-ecosystem: "cargo"
directory: "/"
schedule:
interval: "monthly"
open-pull-requests-limit: 10
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
typed-builder-0.20.0/.github/workflows/ci.yml 0000644 0000000 0000000 00000011605 10461020230 0017172 0 ustar 0000000 0000000 name: CI
on:
pull_request:
push:
branches: [master]
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
checks: write
jobs:
ci:
name: CI
needs: [test, clippy, docs]
runs-on: ubuntu-latest
steps:
- name: Done
run: exit 0
test:
name: Tests
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
rust: [1.70.0, nightly]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
- name: Ready cache
if: matrix.os == 'ubuntu-latest'
run: sudo chown -R $(whoami):$(id -ng) ~/.cargo/
- name: Cache cargo
uses: actions/cache@v4
id: cache
with:
path: ~/.cargo
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Test typed-builder
uses: actions-rs/cargo@v1
with:
command: test
args: --all-targets
nostd-build:
name: nostd Build
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
rust: [nightly]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
target: aarch64-unknown-none
- name: Ready cache
if: matrix.os == 'ubuntu-latest'
run: sudo chown -R $(whoami):$(id -ng) ~/.cargo/
- name: Cache cargo
uses: actions/cache@v4
id: cache
with:
path: ~/.cargo
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Add rustup components
run: rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu
- name: Build with nostd
uses: actions-rs/cargo@v1
with:
command: build
args: -Zbuild-std=core --target aarch64-unknown-none
fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: rustfmt
- name: Run fmt --all -- --check
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: clippy
- name: Cache cargo
uses: actions/cache@v4
id: cache
with:
path: ~/.cargo
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Run clippy --all-targets --
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-targets --
docs:
name: Docs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
- name: Cache cargo
uses: actions/cache@v4
id: cache
with:
path: ~/.cargo
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Run doc tests
uses: actions-rs/cargo@v1
with:
command: test
args: --doc
- name: Check typed-builder docs
uses: actions-rs/cargo@v1
with:
command: doc
args: --no-deps
docs-ghpages:
name: Update Docs in GitHub Pages
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4
- name: Build docs
env:
GITHUB_REPO: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |-
cargo doc --verbose &&
echo "" > target/doc/index.html
- name: Add read permissions
run: |-
chmod --recursive +r target/doc
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: target/doc
deploy-ghpages:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: docs-ghpages
if: github.ref == 'refs/heads/master'
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
typed-builder-0.20.0/.gitignore 0000644 0000000 0000000 00000000560 10461020230 0014445 0 ustar 0000000 0000000 # Generated by Cargo
# will have compiled files and executables
/target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
/target/
**/*.rs.bk
Cargo.lock
/typed-builder-macro/target/
typed-builder-0.20.0/CHANGELOG.md 0000644 0000000 0000000 00000026736 10461020230 0014303 0 ustar 0000000 0000000 # Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [Unreleased]
## 0.20.0 - 2024-08-22
### Added
- Add `#[builder(setter(strip_option(fallback = field_opt)))]` to add a fallback unstripped method to the builder struct.
- Add `#[builder(setter(strip_bool(fallback = field_bool)))]` to add a fallback setter that takes the `bool` value to the builder struct.
## 0.19.1 - 2024-07-14
### Fixed
- Fix mutators for generic fields (see issue #149)
## 0.19.0 - 2024-06-15
### Added
- Use fields' doc comments for the setters.
## 0.18.2 - 2024-04-16
### Fixed
- Also add the licenses to the macro crate.
## 0.18.1 - 2024-01-17
### Fixed
- Add `#[allow(clippy::no_effect_underscore_binding)]` to generated methods
that need to destructure intermediate builder state.
- Use a proper `OR` syntax for the dual license.
## 0.18.0 - 2023-10-19
### Fixed
- `?Sized` generic parameters are now supported.
## 0.17.0 - 2023-10-15
### Changed
- Internal refactor of attribute parsing - results in better error messages and
easier proces for adding new settings.
### Added
- `#[builder(mutators(...))]` to generate functions on builder to mutate fields
- `#[builder(via_mutator)]` on fields to allow defining fields initialized
during `::builder()` for use with `mutators`
- `mutable_during_default_resolution` to allow `default` expression mutate
previous fields.
### Fixed
- Add support for paths with angle brackets (see PR #122 )
## 0.16.2 - 2023-09-22
### Fixed
- Use generics with the constructor in `build` method (see issue #118)
## 0.16.1 - 2023-09-18
### Fixed
- Add `#[allow(clippy::exhaustive_enums)]` to generated empty enums used for
error "reporting" (see issue #112)
- Add `#[automatically_derived]` to generated `impl`s (see issue #114)
- Add `#[allow(clippy::used_underscore_binding)]` to build method and setter
methods (see issue #113)
## 0.16.0 - 2023-08-26
### Added
- `#[builder(crate_module_path = ...)]` for overcoming cases where the derive
macro is used in another crate's macro (see issue #109)
## 0.15.2 - 2023-08-03
### Fixed
- Fix const generics generating "empty" entries in some lists, resulting in
consecutive commas (see issue #106)
## 0.15.1 - 2023-07-10
### Fixed
- no-std build.
## 0.15.0 - 2023-07-06
### Changed
- [**BREAKING**] Split the derive macro out to [a separate procmacro
crate](https://crates.io/crates/typed-builder-macro). This is considered a
breaking change because reexporting and/or renmaing the crate can now prevent
the generated code from finding the types it needs (see issue #101)
### Fixed
- Marking a field as `#[deprecated]` now behaves properly - `TypedBuilder`
generated code itself does trigger the deprecation warning, and instead the
setter for that field now does.
- The "fake" `build` method when required fields are not provided now returns
the never type ("`!`"). Refer to PR #97 for more thorough explanation.
### Added
- Support for setter method prefixes and suffixes `#[builder(field_defaults(setter(prefix = "...", suffix = "...")))]`.
This either prepends or appends the provided string to the setter method. This allows method names like: `set_x()`,
`with_y()`, or `set_z_value()`.
## 0.14.0 - 2023-03-08
### Added
- `build_method(into)` and `build_method(into = ...)`.
## 0.13.0 - 2023-03-05
### Changed
y
- [**BREAKING**] Builder state parameter moved to the end of the generated builder type's parameters list.
- Generated builder type's builder state parameter now defaults to tuple of
empty tuples. This means the empty builder, where no parameter is yet set.
### Fixed
- `#[builder(build_method(...))]` now affects the fake `build` method that's
generated to add information to the compiler error.
## 0.12.0 - 2023-01-29
### Removed
- [**BREAKING**] `builder_method_doc = "..."`, `builder_type_doc = "..."` and
`build_method_doc = "..."` are replaced with `builder_method(doc = "...")`,
`builder_type(doc = "...")` and `build_method(doc = "...")`.
### Added
- `build_method(...)` now has a `doc` field.
- `builder_method(...)` and `builder_type(...)`, which are structured similarly to `build_method(...)`.
## 0.11.0 - 2022-10-29
### Added
- `#[builder(build_method(vis="pub", name=build))]` for customizing visibility and fn name of the final build method
(the default visibility is `pub`, and default build name is `build`)
## 0.10.0 - 2022-02-13
### Added
- `#[builder(setter(strip_bool))]` for making zero arguments setters for `bool` fields that just
set them to `true` (the `default` automatically becomes `false`)
## 0.9.1 - 2021-09-04
### Fixed
- Add `extern crate proc_macro;` to solve some weird problem (https://github.com/idanarye/rust-typed-builder/issues/57)
- Use unambiguous `::` prefixed absolute paths in generated code.
## 0.9.0 - 2021-01-31
### Added
- Builder type implements `Clone` when all set fields support clone.
- `#[builder(setter(transform = ...))]` attribute for running a transform on a
setter's argument to convert them to the field's type.
### Fixed
- Fix code generation for raw identifiers.
## 0.8.0 - 2020-12-06
### Changed
- Upgraded the Rust edition to 2018.
### Added
- `#[field_defaults(...)]` attribute for settings default attributes for all
the fields.
## 0.7.1 - 2020-11-20
### Fixed
- Fix lifetime bounds erroneously preserved in phantom generics.
## 0.7.0 - 2020-07-23
### Added
- Brought back `default_code`, because it needed to resolve conflict with other
custom derive proc-macro crates that try to parse `[#builder(default = ...)]`
attribute in order to decide if they are relevant to them - and fail because
the expect them to be simple literals.
## 0.6.0 - 2020-05-18
### Added
- Ability to use `into` and `strip_option` simultaneously for a field.
### Changed
- [**BREAKING**] Specifying `skip` twice in the same `builder(setter(...))` is
no longer supported. Then again, if you were doing that you probably deserve
having your code broken.
## 0.5.1 - 2020-01-26
### Fixed
- Prevent Clippy from warning about the `panic!()` in the faux build method.
## 0.5.0 - 2020-01-25
### Changed
- [**BREAKING**] Move `doc` and `skip` into a subsetting named `setter(...)`.
This means that `#[builder(doc = "...")]`, for example, should now be written
as `#[builder(setter(doc = "..."))]`.
- [**BREAKING**] Setter arguments by default are no longer automatically
converted to the target type with `into()`. If you want to automatically
convert them, use `#[builder(setter(into))]`. This new default enables rustc
inference for generic types and proper integer literal type detection.
- Improve build errors for incomplete `.build()` and repeated setters, by
creating faux methods with deprecation warnings.
### Added
- `#[builder(setter(strip_option))]` for making setters for `Option` fields
automatically wrap the argument with `Some(...)`. Note that this is a weaker
conversion than `#[builder(setter(into))]`, and thus can still support type
inference and integer literal type detection.
### Removed
- [**BREAKING**] Removed the `default_code` setting (`#[builder(default_code =
"...")]`) because it is no longer required now that Rust and `syn` support
arbitrary expressions in attributes.
## 0.4.1 - 2020-01-17
### Fixed
- [**BREAKING**] now state types are placed before original generic types.
Previously, all state types are appended to generic arguments. For example,
`Foo<'a, X, Y>` yields `FooBuilder<'a, X, Y, ((), ())>` **previously**, and
now it becomes `FooBuilder<'a, ((), ()), X, Y, >.`. This change fix compiler error
for struct with default type like `Foo<'a, X, Y=Bar>`. Rust only allow type
parameters with a default to be trailing.
## 0.4.0 - 2019-12-13
### Added
- `#![no_std]` is now supported out of the box. (You don't need to opt into any
features, it just works.)
- [**BREAKING**] a `default_code` expression can now refer to the values of
earlier fields by name (This is extremely unlikely to break your code, but
could in theory due to shadowing)
- `#[builder(skip)]` on fields, to not provide a method to set that field.
- Control of documentation:
- `#[builder(doc = "…")]` on fields, to document the field's method on the
builder. Unlike `#[doc]`, you can currently only have one value rather than
one attribute per line; but that's not a big deal since you don't get to
use the `///` sugar anyway. Just use a multiline string.
- `#[builder(doc, builder_method_doc = "…", builder_type_doc = "…",
build_method_doc = "…")]` on structs:
- `doc` unhides the builder type from the documentation.
- `builder_method_doc = "…"` replaces the default documentation that
will be generated for the builder() method of the type for which the
builder is being generated.
- `builder_type_doc = "…"` replaces the default documentation that will
be generated for the builder type. Implies `doc`.
- `build_method_doc = "…"` replaces the default documentation that will
be generated for the build() method of the builder type. Implies
`doc`.
### Changed
- [**BREAKING**] Renamed the generated builder type from
`TypedBuilder_BuilderFor_Foo` to `FooBuilder`, for improved ergonomics,
especially when you enable documentation of the builder type.
- Generic identifiers were also changed, from `TypedBuilder_genericType_x` to
`__x`. This is still expected to avoid all name collisions, but is easier
to read in the builder type docs if you enable them.
- Renamed the conversion helper trait for documentation purposes
(`TypedBuilder_conversionHelperTrait_Foo` to `FooBuilder_Optional`), and
its method name for simpler code.
- [**BREAKING**] `default_code` is now lazily evaluated instead of eagerly; any
side-effects that there might have been will no longer occur. As is usual in
this release, this is very unlikely to affect you.
- The restriction that there be only one `#[builder]` attribute per field has
been lifted. You can now write `#[builder(skip)] #[builder(default)]` instead
of `#[builder(skip, default)]` if you want to. As was already the case,
latest definition wins.
- [**BREAKING**] Use a single generic parameter to represent the builder type's
state (see issue #21). Previously we would use a parameter for each field.
### Changed
- Move to dual license - MIT/Apache-2.0. Previously this project was just MIT.
## 0.3.0 - 2019-02-19
### Added
- `#[builder(default_code = "...")]` syntax for defaults that cannot be parsed
as attributes no matter what.
### Changed
- Move the docs from the crate to the custom derive proc macro.
## 0.2.0 - 2019-02-06
### Changed
- Upgraded `syn` version to support Rust 2018.
- [**BREAKING**] Changed attribute style to `#[builder(...)]`:
- `#[default]` -> `#[builder(default)]`
- `#[default=...]` -> `#[builder(default=...)]`
- [**BREAKING**] `default` no longer needs to be a string.
- But you need to change your code anyways because the attribute style was changed.
## 0.1.1 - 2018-07-24
### Fixed
- Allow missing docs in structs that derive `TypedBuilder`.
## 0.1.0 - 2017-10-05
### Added
- Custom derive for generating the builder pattern.
- All setters are accepting `Into` values.
- Compile time verification that all fields are set before calling `.build()`.
- Compile time verification that no field is set more than once.
- Ability to annotate fields with `#[default]` to make them optional and specify a default value when the user does not set them.
- Generates simple documentation for the `.builder()` method.
typed-builder-0.20.0/Cargo.lock 0000644 00000002525 00000000001 0011643 0 ustar # This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "proc-macro2"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
dependencies = [
"proc-macro2",
]
[[package]]
name = "syn"
version = "2.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "typed-builder"
version = "0.20.0"
dependencies = [
"typed-builder-macro",
]
[[package]]
name = "typed-builder-macro"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "560b82d656506509d43abe30e0ba64c56b1953ab3d4fe7ba5902747a7a3cedd5"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
typed-builder-0.20.0/Cargo.toml 0000644 00000002742 00000000001 0011667 0 ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
name = "typed-builder"
version = "0.20.0"
authors = [
"IdanArye ",
"Chris Morgan ",
]
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Compile-time type-checked builder derive"
documentation = "https://idanarye.github.io/rust-typed-builder/"
readme = "README.md"
keywords = ["builder"]
categories = ["rust-patterns"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/idanarye/rust-typed-builder"
[lib]
name = "typed_builder"
path = "src/lib.rs"
[[example]]
name = "complicate_build"
path = "examples/complicate_build.rs"
[[example]]
name = "example"
path = "examples/example.rs"
[[example]]
name = "example_prefix_suffix"
path = "examples/example_prefix_suffix.rs"
[[test]]
name = "no_std"
path = "tests/no_std.rs"
[[test]]
name = "no_type_leakage"
path = "tests/no_type_leakage.rs"
[[test]]
name = "tests"
path = "tests/tests.rs"
[dependencies.typed-builder-macro]
version = "=0.20.0"
typed-builder-0.20.0/Cargo.toml.orig 0000644 0000000 0000000 00000001551 10461020230 0015345 0 ustar 0000000 0000000 [workspace]
members = [".", "./typed-builder-macro"]
[workspace.package]
description = "Compile-time type-checked builder derive"
version = "0.20.0"
authors = ["IdanArye ", "Chris Morgan "]
edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/idanarye/rust-typed-builder"
documentation = "https://idanarye.github.io/rust-typed-builder/"
readme = "README.md"
keywords = ["builder"]
categories = ["rust-patterns"]
[package]
name = "typed-builder"
description.workspace = true
version.workspace = true
authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
documentation.workspace = true
readme.workspace = true
keywords.workspace = true
categories.workspace = true
[dependencies]
typed-builder-macro = { path = "typed-builder-macro", version = "=0.20.0" }
typed-builder-0.20.0/LICENSE-APACHE 0000644 0000000 0000000 00000025137 10461020230 0014410 0 ustar 0000000 0000000 Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
typed-builder-0.20.0/LICENSE-MIT 0000644 0000000 0000000 00000001777 10461020230 0014124 0 ustar 0000000 0000000 Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
typed-builder-0.20.0/README.md 0000644 0000000 0000000 00000007556 10461020230 0013750 0 ustar 0000000 0000000 [](https://github.com/idanarye/rust-typed-builder/actions)
[](https://crates.io/crates/typed-builder)
[](https://idanarye.github.io/rust-typed-builder/)
# Rust Typed Builder
Creates a compile-time verified builder:
```rust
use typed_builder::TypedBuilder;
#[derive(TypedBuilder)]
struct Foo {
// Mandatory Field:
x: i32,
// #[builder(default)] without parameter - use the type's default
// #[builder(setter(strip_option))] - wrap the setter argument with `Some(...)`
#[builder(default, setter(strip_option))]
y: Option,
// Or you can set the default
#[builder(default=20)]
z: i32,
}
```
Build in any order:
```rust
Foo::builder().x(1).y(2).z(3).build();
Foo::builder().z(1).x(2).y(3).build();
```
Omit optional fields(the one marked with `#[default]`):
```rust
Foo::builder().x(1).build()
```
But you can't omit non-optional arguments - or it won't compile:
```rust
Foo::builder().build(); // missing x
Foo::builder().x(1).y(2).y(3); // y is specified twice
```
## Features
* Custom derive for generating the builder pattern.
* Ability to annotate fields with `#[builder(setter(into))]` to make their setters accept `Into` values.
* Compile time verification that all fields are set before calling `.build()`.
* Compile time verification that no field is set more than once.
* Ability to annotate fields with `#[builder(default)]` to make them optional and specify a default value when the user does not set them.
* Generates simple documentation for the `.builder()` method.
* Customizable method name and visibility of the `.build()` method.
## Limitations
* 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.
* 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).
* 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...
* 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.
## Conflicts
* `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.
## Alternatives - and why typed-builder is better
* [derive-builder](https://crates.io/crates/derive_builder) - does all the checks in runtime, returning a `Result` you need to unwrap.
* [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.
## License
Licensed under either of
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
additional terms or conditions.
typed-builder-0.20.0/examples/complicate_build.rs 0000644 0000000 0000000 00000003216 10461020230 0020141 0 ustar 0000000 0000000 #![allow(clippy::disallowed_names)]
mod scope {
use typed_builder::TypedBuilder;
#[derive(Debug, PartialEq, TypedBuilder)]
#[builder(build_method(vis="", name=__build))]
pub struct Foo {
// Mandatory Field:
x: i32,
// #[builder(default)] without parameter - use the type's default
// #[builder(setter(strip_option))] - wrap the setter argument with `Some(...)`
#[builder(default, setter(strip_option))]
y: Option,
// Or you can set the default
#[builder(default = 20)]
z: i32,
}
// Customize build method to add complicated logic.
//
// The signature might be frightening at first glance,
// but we don't need to infer this whole ourselves.
//
// We can use `cargo expand` to show code expanded by `TypedBuilder`,
// copy the generated `__build` method, and modify the content of the build method.
#[allow(non_camel_case_types)]
impl<__z: typed_builder::Optional, __y: typed_builder::Optional