Skip to content

Implement Channel API w/Type Builder#2633

Draft
nathanielford wants to merge 2 commits into
hyperium:masterfrom
nathanielford:implement/ChannelTypeBuilder
Draft

Implement Channel API w/Type Builder#2633
nathanielford wants to merge 2 commits into
hyperium:masterfrom
nathanielford:implement/ChannelTypeBuilder

Conversation

@nathanielford
Copy link
Copy Markdown
Collaborator

Motivation

The Channel object needs a stable API with which users can easily create and manipulate a channel. The current object works, but requires something more ergonomic from both a user and maintenance perspective. This draft is to demonstrate how a type-builder value accumulation API might look like.

This is just a draft, meant to elaborate on one approach.

Solution

This uses a type builder to allows a user to do the following:

let creds = get_channel_credentials();
let custom_rt = get_custom_runtime(); // Instance of `GrpcRuntime`

let channel = Channel::builder("http://[::1]:50051")
    .with_credentials(creds)
    .with_runtime(custom_rt)
    .build();

Similarly, if the tokio feature flag was implemented and the user wanted to use the default runtime they could do the following:

let creds = get_channel_credentials();
let channel = Channel::builder("http://[::1]:50051")
    .with_credentials(creds)
    .build();

Additional options could be chained on to the builder, as normal.

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.

1 participant