Skip to content

client: ClientConfig/CallOptions accessors, rename builders to with_* - #100

Merged
iainmcgin merged 3 commits into
mainfrom
iainmcgin/issue-90-client-config-encapsulation
May 15, 2026
Merged

iainmcgin merged 3 commits into
mainfrom
iainmcgin/issue-90-client-config-encapsulation

Conversation

@iainmcgin

Copy link
Copy Markdown
Collaborator

Fixes #90.

ClientConfig and CallOptions are #[non_exhaustive] with pub fields. 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 ClientConfig setter methods are renamed to the with_* form already used by CallOptions:

Before After
.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 all CallOptions builder 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

// before
let config = ClientConfig::new(uri).protocol(Protocol::Grpc);
let timeout = options.timeout;

// after
let config = ClientConfig::new(uri).with_protocol(Protocol::Grpc);
let timeout = options.timeout();

Out of scope

The issue also flags the invalid-header policy inconsistency (Response::with_header panics on invalid input; ClientConfig::with_default_header and CallOptions::with_header silently drop). Tracking that separately to keep this PR focused on the construction/encapsulation change.

Reviewer notes

ClientConfig::with_compression(registry: CompressionRegistry) and CallOptions::with_compression(enabled: bool) now share a name with different argument types. This asymmetry pre-existed (compression(registry) vs with_compression(enabled)); the rename just makes it visible. Happy to rename ClientConfig::with_compression to something like with_compression_registry if the collision is too confusing.

SemVer: breaking. Lands in the 0.5.0 bump alongside the streaming-trait type Item: Encodable<Res> change already on main.

@github-actions

github-actions Bot commented May 14, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

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
iainmcgin force-pushed the iainmcgin/issue-90-client-config-encapsulation branch from c3de9f1 to a6b5502 Compare May 14, 2026 22:16
@iainmcgin
iainmcgin marked this pull request as ready for review May 14, 2026 22:30
@iainmcgin
iainmcgin requested a review from rpb-ant May 14, 2026 22:30
@iainmcgin
iainmcgin enabled auto-merge (squash) May 15, 2026 02:59
@iainmcgin
iainmcgin merged commit e745db1 into main May 15, 2026
20 of 23 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators May 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClientConfig / CallOptions: #[non_exhaustive] + pub fields blocks all construction outside the crate

2 participants