pub struct Channel { /* private fields */ }
Expand description
A default batteries included transport
channel.
This provides a fully featured http2 gRPC client based on hyper::Client
and tower
services.
§Multiplexing requests
Sending a request on a channel requires a &mut self
and thus can only send
one request in flight. This is intentional and is required to follow the Service
contract from the tower
library which this channel implementation is built on
top of.
tower
itself has a concept of poll_ready
which is the main mechanism to apply
back pressure. poll_ready
takes a &mut self
and when it returns Poll::Ready
we know the Service
is able to accept only one request before we must poll_ready
again. Due to this fact any async fn
that wants to poll for readiness and submit
the request must have a &mut self
reference.
To work around this and to ease the use of the channel, Channel
provides a
Clone
implementation that is cheap. This is because at the very top level
the channel is backed by a tower_buffer::Buffer
which runs the connection
in a background task and provides a mpsc
channel interface. Due to this
cloning the Channel
type is cheap and encouraged.
Implementations§
source§impl Channel
impl Channel
sourcepub fn from_static(s: &'static str) -> Endpoint
pub fn from_static(s: &'static str) -> Endpoint
Create an Endpoint
from a static string.
Channel::from_static("https://example.com");
Create an Endpoint
from shared bytes.
Channel::from_shared("https://example.com");
sourcepub fn balance_list(list: impl Iterator<Item = Endpoint>) -> Self
pub fn balance_list(list: impl Iterator<Item = Endpoint>) -> Self
sourcepub fn balance_channel<K>(
capacity: usize,
) -> (Self, Sender<Change<K, Endpoint>>)
pub fn balance_channel<K>( capacity: usize, ) -> (Self, Sender<Change<K, Endpoint>>)
sourcepub fn balance_channel_with_executor<K, E>(
capacity: usize,
executor: E,
) -> (Self, Sender<Change<K, Endpoint>>)
pub fn balance_channel_with_executor<K, E>( capacity: usize, executor: E, ) -> (Self, Sender<Change<K, Endpoint>>)
Trait Implementations§
source§impl Service<Request<UnsyncBoxBody<Bytes, Status>>> for Channel
impl Service<Request<UnsyncBoxBody<Bytes, Status>>> for Channel
Auto Trait Implementations§
impl Freeze for Channel
impl !RefUnwindSafe for Channel
impl Send for Channel
impl Sync for Channel
impl Unpin for Channel
impl !UnwindSafe for Channel
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§impl<T, ReqBody, ResBody> GrpcService<ReqBody> for T
impl<T, ReqBody, ResBody> GrpcService<ReqBody> for T
source§type ResponseBody = ResBody
type ResponseBody = ResBody
source§fn poll_ready(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<(), <T as GrpcService<ReqBody>>::Error>>
fn poll_ready( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<(), <T as GrpcService<ReqBody>>::Error>>
Ready
when the service is able to process requests. Read moresource§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
§impl<S, R> ServiceExt<R> for Swhere
S: Service<R>,
impl<S, R> ServiceExt<R> for Swhere
S: Service<R>,
§fn into_make_service(self) -> IntoMakeService<S>
fn into_make_service(self) -> IntoMakeService<S>
MakeService
, that is a Service
whose
response is another service. Read more§impl<T, Request> ServiceExt<Request> for T
impl<T, Request> ServiceExt<Request> for T
§fn ready(&mut self) -> Ready<'_, Self, Request> ⓘwhere
Self: Sized,
fn ready(&mut self) -> Ready<'_, Self, Request> ⓘwhere
Self: Sized,
§fn ready_and(&mut self) -> Ready<'_, Self, Request> ⓘwhere
Self: Sized,
fn ready_and(&mut self) -> Ready<'_, Self, Request> ⓘwhere
Self: Sized,
ServiceExt::ready
method instead§fn ready_oneshot(self) -> ReadyOneshot<Self, Request> ⓘwhere
Self: Sized,
fn ready_oneshot(self) -> ReadyOneshot<Self, Request> ⓘwhere
Self: Sized,
§fn oneshot(self, req: Request) -> Oneshot<Self, Request> ⓘwhere
Self: Sized,
fn oneshot(self, req: Request) -> Oneshot<Self, Request> ⓘwhere
Self: Sized,
Service
, calling with the providing request once it is ready.§fn and_then<F>(self, f: F) -> AndThen<Self, F>
fn and_then<F>(self, f: F) -> AndThen<Self, F>
poll_ready
method. Read more§fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
poll_ready
method. Read more§fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
poll_ready
method. Read more§fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
Result<Self::Response, Self::Error>
)
to a different value, regardless of whether the future succeeds or
fails. Read more