Skip to content

Make client construction typesafe - #336

Open
itsibitzi wants to merge 1 commit into
mainfrom
itsibitzi/20260715-typesafe-client-construction
Open

Make client construction typesafe#336
itsibitzi wants to merge 1 commit into
mainfrom
itsibitzi/20260715-typesafe-client-construction

Conversation

@itsibitzi

@itsibitzi itsibitzi commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Use zero size types to make it impossible to mix direct and HTTP client functions during construction. Previously this was a panic.

This shouldn't change any code when a client is just calling the direct() function, but return types and parameter types will need to be updated if folks are passing around a builder.

@itsibitzi
itsibitzi requested a review from a team as a code owner July 15, 2026 10:27
Copilot AI review requested due to automatic review settings July 15, 2026 10:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces typestate-based client construction to prevent mixing HTTP and direct-only methods.

Changes:

  • Adds Http and Direct builder modes.
  • Moves mode-specific methods into specialized implementations.
  • Adds compile-fail documentation examples.
Show a summary per file
File Description
crates/twirp/src/client.rs Implements type-safe HTTP and direct client builders.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Medium

/// twirp::ClientBuilder::new(url)
/// .with_default_header("x-request-id", HeaderValue::from_static("example"));
/// ```
pub struct ClientBuilder<T = Http> {
Base automatically changed from itsibitzi/20260715-client-kind to main July 15, 2026 10:53
@itsibitzi
itsibitzi force-pushed the itsibitzi/20260715-typesafe-client-construction branch from 59f09d8 to 7ccda90 Compare July 15, 2026 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants