Repository navigation
client: ClientConfig/CallOptions accessors, rename builders to with_* - #100
Merged
Merged
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
ClientConfig and CallOptions are #[non_exhaustive] with pub fields — the worst-of-both-worlds combination. Rustdoc shows pub fields, the user reaches for struct-literal or functional-update construction, and gets E0639 with no pointer at the builder methods. This change makes the construction story and the rustdoc agree. - Fields are now pub(crate). Reads go through same-named accessors (`config.protocol()`, `config.base_uri()`, `options.timeout()`, `options.headers()`, …). - ClientConfig setter methods rename to `with_*` to free the bare names for accessors and align with CallOptions, which already used `with_*`: `.protocol(p)` -> `.with_protocol(p)`, `.codec_format(f)` -> `.with_codec_format(f)`, `.compression(r)` -> `.with_compression(r)`, `.compression_policy(p)` -> `.with_compression_policy(p)`, `.default_timeout(t)` -> `.with_default_timeout(t)`, `.default_max_message_size(s)` -> `.with_default_max_message_size(s)`, `.default_header(n,v)` -> `.with_default_header(n,v)`, `.default_headers(h)` -> `.with_default_headers(h)`. `new`, `json`, `proto`, and `compress_requests` are unchanged. - All workspace consumers updated mechanically; the codegen template's example docstring updated and the four checked-in generated directories regenerated (docstring-only diff). SemVer: breaking. Lands in the 0.5.0 bump alongside the streaming-trait changes already in main. Out of scope: unifying the invalid-header policy (silent drop vs panic) between Response::with_header and ClientConfig::with_default_header / CallOptions::with_header. Tracked separately to keep this PR focused. Fixes #90.
iainmcgin
force-pushed
the
iainmcgin/issue-90-client-config-encapsulation
branch
from
May 14, 2026 22:16
c3de9f1 to
a6b5502
Compare
iainmcgin
marked this pull request as ready for review
May 14, 2026 22:30
rpb-ant
approved these changes
May 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #90.
ClientConfigandCallOptionsare#[non_exhaustive]withpubfields. Rustdoc shows pub fields, the user reaches for struct-literal or functional-update construction, and gets E0639 with no pointer at the builder methods. This change makes the construction story and the rustdoc agree.What changed
Fields are now
pub(crate). Reads go through same-named accessors:config.protocol(),config.base_uri(),options.timeout(),options.headers(), etc.To free the bare names for accessors, the
ClientConfigsetter methods are renamed to thewith_*form already used byCallOptions:.protocol(p).with_protocol(p).codec_format(f).with_codec_format(f).compression(r).with_compression(r).compression_policy(p).with_compression_policy(p).default_timeout(t).with_default_timeout(t).default_max_message_size(s).with_default_max_message_size(s).default_header(n, v).with_default_header(n, v).default_headers(h).with_default_headers(h)ClientConfig::new(uri),.json(),.proto(),.compress_requests(e), and allCallOptionsbuilder methods are unchanged.All workspace consumers (conformance client, examples, benches, tests, docs) updated mechanically. The codegen template's generated client docstring updated and the four checked-in generated directories regenerated — docstring-only diff there.
Migration
Out of scope
The issue also flags the invalid-header policy inconsistency (
Response::with_headerpanics on invalid input;ClientConfig::with_default_headerandCallOptions::with_headersilently drop). Tracking that separately to keep this PR focused on the construction/encapsulation change.Reviewer notes
ClientConfig::with_compression(registry: CompressionRegistry)andCallOptions::with_compression(enabled: bool)now share a name with different argument types. This asymmetry pre-existed (compression(registry)vswith_compression(enabled)); the rename just makes it visible. Happy to renameClientConfig::with_compressionto something likewith_compression_registryif the collision is too confusing.SemVer: breaking. Lands in the 0.5.0 bump alongside the streaming-trait
type Item: Encodable<Res>change already onmain.