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
sourceimpl 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
Trait Implementations
sourceimpl Service<Request<UnsyncBoxBody<Bytes, Status>>> for Channel
impl Service<Request<UnsyncBoxBody<Bytes, Status>>> for Channel
type Future = ResponseFuture
type Future = ResponseFuture
sourcefn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
Poll::Ready(Ok(()))
when the service is able to process requests. Read moreAuto Trait Implementations
impl !RefUnwindSafe for Channel
impl Send for Channel
impl Sync for Channel
impl Unpin for Channel
impl !UnwindSafe for Channel
Blanket Implementations
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstablefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T>where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T>where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourcefn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T>where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T>where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T>where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T>where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourcefn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T>where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T>where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourceimpl<T, Request> ServiceExt<Request> for Twhere
T: Service<Request> + ?Sized,
impl<T, Request> ServiceExt<Request> for Twhere
T: Service<Request> + ?Sized,
sourcefn ready(&mut self) -> Ready<'_, Self, Request>ⓘNotable traits for Ready<'a, T, Request>impl<'a, T, Request> Future for Ready<'a, T, Request>where
T: Service<Request>, type Output = Result<&'a mut T, <T as Service<Request>>::Error>;
fn ready(&mut self) -> Ready<'_, Self, Request>ⓘNotable traits for Ready<'a, T, Request>impl<'a, T, Request> Future for Ready<'a, T, Request>where
T: Service<Request>, type Output = Result<&'a mut T, <T as Service<Request>>::Error>;
T: Service<Request>, type Output = Result<&'a mut T, <T as Service<Request>>::Error>;
sourcefn ready_and(&mut self) -> Ready<'_, Self, Request>ⓘNotable traits for Ready<'a, T, Request>impl<'a, T, Request> Future for Ready<'a, T, Request>where
T: Service<Request>, type Output = Result<&'a mut T, <T as Service<Request>>::Error>;
fn ready_and(&mut self) -> Ready<'_, Self, Request>ⓘNotable traits for Ready<'a, T, Request>impl<'a, T, Request> Future for Ready<'a, T, Request>where
T: Service<Request>, type Output = Result<&'a mut T, <T as Service<Request>>::Error>;
T: Service<Request>, type Output = Result<&'a mut T, <T as Service<Request>>::Error>;
ServiceExt::ready
method insteadsourcefn ready_oneshot(self) -> ReadyOneshot<Self, Request>ⓘNotable traits for ReadyOneshot<T, Request>impl<T, Request> Future for ReadyOneshot<T, Request>where
T: Service<Request>, type Output = Result<T, <T as Service<Request>>::Error>;
fn ready_oneshot(self) -> ReadyOneshot<Self, Request>ⓘNotable traits for ReadyOneshot<T, Request>impl<T, Request> Future for ReadyOneshot<T, Request>where
T: Service<Request>, type Output = Result<T, <T as Service<Request>>::Error>;
T: Service<Request>, type Output = Result<T, <T as Service<Request>>::Error>;
sourcefn oneshot(self, req: Request) -> Oneshot<Self, Request>ⓘNotable traits for Oneshot<S, Req>impl<S, Req> Future for Oneshot<S, Req>where
S: Service<Req>, type Output = Result<<S as Service<Req>>::Response, <S as Service<Req>>::Error>;
fn oneshot(self, req: Request) -> Oneshot<Self, Request>ⓘNotable traits for Oneshot<S, Req>impl<S, Req> Future for Oneshot<S, Req>where
S: Service<Req>, type Output = Result<<S as Service<Req>>::Response, <S as Service<Req>>::Error>;
S: Service<Req>, type Output = Result<<S as Service<Req>>::Response, <S as Service<Req>>::Error>;
Service
, calling with the providing request once it is ready.sourcefn call_all<S>(self, reqs: S) -> CallAll<Self, S>where
Self::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
S: Stream<Item = Request>,
fn call_all<S>(self, reqs: S) -> CallAll<Self, S>where
Self::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
S: Stream<Item = Request>,
sourcefn and_then<F>(self, f: F) -> AndThen<Self, F>where
F: Clone,
fn and_then<F>(self, f: F) -> AndThen<Self, F>where
F: Clone,
poll_ready
method. Read moresourcefn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>where
F: FnOnce(Self::Response) -> Response + Clone,
fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>where
F: FnOnce(Self::Response) -> Response + Clone,
poll_ready
method. Read moresourcefn map_err<F, Error>(self, f: F) -> MapErr<Self, F>where
F: FnOnce(Self::Error) -> Error + Clone,
fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>where
F: FnOnce(Self::Error) -> Error + Clone,
poll_ready
method. Read moresourcefn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>where
Error: From<Self::Error>,
F: FnOnce(Result<Self::Response, Self::Error>) -> Result<Response, Error> + Clone,
fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>where
Error: From<Self::Error>,
F: FnOnce(Result<Self::Response, Self::Error>) -> Result<Response, Error> + Clone,
Result<Self::Response, Self::Error>
)
to a different value, regardless of whether the future succeeds or
fails. Read moresourcefn map_request<F, NewRequest>(self, f: F) -> MapRequest<Self, F>where
F: FnMut(NewRequest) -> Request,
fn map_request<F, NewRequest>(self, f: F) -> MapRequest<Self, F>where
F: FnMut(NewRequest) -> Request,
sourcefn then<F, Response, Error, Fut>(self, f: F) -> Then<Self, F>where
Error: From<Self::Error>,
F: FnOnce(Result<Self::Response, Self::Error>) -> Fut + Clone,
Fut: Future<Output = Result<Response, Error>>,
fn then<F, Response, Error, Fut>(self, f: F) -> Then<Self, F>where
Error: From<Self::Error>,
F: FnOnce(Result<Self::Response, Self::Error>) -> Fut + Clone,
Fut: Future<Output = Result<Response, Error>>,
sourcefn map_future<F, Fut, Response, Error>(self, f: F) -> MapFuture<Self, F>where
F: FnMut(Self::Future) -> Fut,
Error: From<Self::Error>,
Fut: Future<Output = Result<Response, Error>>,
fn map_future<F, Fut, Response, Error>(self, f: F) -> MapFuture<Self, F>where
F: FnMut(Self::Future) -> Fut,
Error: From<Self::Error>,
Fut: Future<Output = Result<Response, Error>>,
sourcefn boxed(self) -> BoxService<Request, Self::Response, Self::Error>where
Self: 'static + Send,
Self::Future: 'static + Send,
fn boxed(self) -> BoxService<Request, Self::Response, Self::Error>where
Self: 'static + Send,
Self::Future: 'static + Send,
sourcefn boxed_clone(self) -> BoxCloneService<Request, Self::Response, Self::Error>where
Self: 'static + Clone + Send,
Self::Future: 'static + Send,
fn boxed_clone(self) -> BoxCloneService<Request, Self::Response, Self::Error>where
Self: 'static + Clone + Send,
Self::Future: 'static + Send,
impl<T> ToOwned for Twhere
T: Clone,
impl<T> ToOwned for Twhere
T: Clone,
type Owned = T
type Owned = T
fn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T>where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T>where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
T: Future, type Output = <T as Future>::Output;
sourcefn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T>where
T: Future, type Output = <T as Future>::Output;
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T>where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T>where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T>where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
T: Future, type Output = <T as Future>::Output;
sourcefn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T>where
T: Future, type Output = <T as Future>::Output;
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T>where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;