Commit a870a3d
Round out builder coverage and document the Option<T> escape hatch
After landing per-field builders on the four highest-traffic
consumer-facing config structs (MessageOptions, ClientOptions, Tool,
SessionConfig/ResumeSessionConfig), this commit closes the long tail.
Rust ecosystem research (tokio, reqwest, tonic, axum, AWS SDK) confirms
two design points:
1. The dominant pattern for #[non_exhaustive] config builders is the
single `with_<field>(impl Into<T>) -> Self` setter that always
Some-wraps. AWS SDK's dual `field` + `set_field(Option<T>)` shape
is justified by codegen, not by ergonomics — and the
`impl Into<Option<T>>` magic that some older crates use has fallen
out of fashion (it conflicts with `impl Into<T>` chaining and
produces poor type-inference errors).
2. Direct field assignment on a `pub` field is idiomatic Rust for
forwarding `Option<T>` values from upstream code. The
http::request::Parts / hyper::Body::Builder pattern. We already
support it; we just hadn't documented it.
This commit therefore:
- Adds full builders to the four bare consumer-facing structs:
CustomAgentConfig (name + prompt required, six with_* setters),
InfiniteSessionConfig (three with_* setters), ProviderConfig
(base_url required, six with_* setters), SystemMessageConfig
(three with_* setters).
- Expands TraceContext with a symmetric new() + with_traceparent pair
alongside the existing from_traceparent shorthand. The shorthand
is now expressed in terms of the chain (`new().with_traceparent(x)`)
for consistency.
- Documents the direct-field-assignment escape hatch on SessionConfig
and ResumeSessionConfig, with a doc example showing how to mix the
fluent chain (for compile-time-known values) with direct mutation
(for Option<T> pass-throughs).
Per-field `with_<x>_opt(Option<T>)` setters were considered and
deliberately rejected: doubling the method count for ~30-field
configs would hurt rustdoc discoverability and conflict with the
single-setter precedent we just shipped. The mut-let escape hatch
covers the same use case without polluting the API surface.
Adds 5 unit tests (one per new builder + a TraceContext suite) and
extends the existing CHANGELOG "Builder ergonomics" subsection.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent e93ce8e commit a870a3d
3 files changed
Lines changed: 358 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
381 | 381 | | |
382 | 382 | | |
383 | 383 | | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
384 | 403 | | |
385 | 404 | | |
386 | 405 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
38 | 44 | | |
39 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
40 | 49 | | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
45 | 58 | | |
46 | 59 | | |
47 | 60 | | |
| |||
87 | 100 | | |
88 | 101 | | |
89 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
0 commit comments