pub struct ServiceClient<T> { /* private fields */ }Expand description
Client for this service.
Generic over T: ClientTransport. For gRPC (HTTP/2), use
Http2Connection — it has honest poll_ready and composes with
tower::balance for multi-connection load balancing. For Connect
over HTTP/1.1 (or unknown protocol), use HttpClient.
§Example (gRPC / HTTP/2)
use connectrpc::client::{Http2Connection, ClientConfig};
use connectrpc::Protocol;
let uri: http::Uri = "http://localhost:8080".parse()?;
let conn = Http2Connection::connect_plaintext(uri.clone()).await?.shared(1024);
let config = ClientConfig::new(uri).with_protocol(Protocol::Grpc);
let client = ServiceClient::new(conn, config);
let response = client.subscribe(request).await?;§Example (Connect / HTTP/1.1 or ALPN)
use connectrpc::client::{HttpClient, ClientConfig};
let http = HttpClient::plaintext(); // cleartext http:// only
let config = ClientConfig::new("http://localhost:8080".parse()?);
let client = ServiceClient::new(http, config);
let response = client.subscribe(request).await?;§Working with the response
Unary calls return UnaryResponse<OwnedView<FooView>>.
The OwnedView derefs to the view, so field access is zero-copy:
let resp = client.subscribe(request).await?.into_view();
let name: &str = resp.name; // borrow into the response bufferIf you need the owned struct (e.g. to store or pass by value), use
into_owned():
let owned = client.subscribe(request).await?.into_owned();Implementations§
Source§impl<T> ServiceClient<T>
impl<T> ServiceClient<T>
Sourcepub fn new(transport: T, config: ClientConfig) -> Self
pub fn new(transport: T, config: ClientConfig) -> Self
Create a new client with the given transport and configuration.
Sourcepub fn config(&self) -> &ClientConfig
pub fn config(&self) -> &ClientConfig
Get the client configuration.
Sourcepub fn config_mut(&mut self) -> &mut ClientConfig
pub fn config_mut(&mut self) -> &mut ClientConfig
Get a mutable reference to the client configuration.
Sourcepub async fn subscribe(
&self,
request: SubscribeRequest,
) -> Result<ServerStream<T::ResponseBody, SubscribeResponseView<'static>>, ConnectError>
pub async fn subscribe( &self, request: SubscribeRequest, ) -> Result<ServerStream<T::ResponseBody, SubscribeResponseView<'static>>, ConnectError>
Call the Subscribe RPC. Sends a request to /sql.v1.Service/Subscribe.
Sourcepub async fn subscribe_with_options(
&self,
request: SubscribeRequest,
options: CallOptions,
) -> Result<ServerStream<T::ResponseBody, SubscribeResponseView<'static>>, ConnectError>
pub async fn subscribe_with_options( &self, request: SubscribeRequest, options: CallOptions, ) -> Result<ServerStream<T::ResponseBody, SubscribeResponseView<'static>>, ConnectError>
Call the Subscribe RPC with explicit per-call options. Options override ClientConfig defaults.
Sourcepub async fn query(
&self,
request: QueryRequest,
) -> Result<UnaryResponse<OwnedView<QueryResponseView<'static>>>, ConnectError>
pub async fn query( &self, request: QueryRequest, ) -> Result<UnaryResponse<OwnedView<QueryResponseView<'static>>>, ConnectError>
Call the Query RPC. Sends a request to /sql.v1.Service/Query.
Sourcepub async fn query_with_options(
&self,
request: QueryRequest,
options: CallOptions,
) -> Result<UnaryResponse<OwnedView<QueryResponseView<'static>>>, ConnectError>
pub async fn query_with_options( &self, request: QueryRequest, options: CallOptions, ) -> Result<UnaryResponse<OwnedView<QueryResponseView<'static>>>, ConnectError>
Call the Query RPC with explicit per-call options. Options override ClientConfig defaults.
Sourcepub async fn tables(
&self,
request: TablesRequest,
) -> Result<UnaryResponse<OwnedView<TablesResponseView<'static>>>, ConnectError>
pub async fn tables( &self, request: TablesRequest, ) -> Result<UnaryResponse<OwnedView<TablesResponseView<'static>>>, ConnectError>
Call the Tables RPC. Sends a request to /sql.v1.Service/Tables.
Sourcepub async fn tables_with_options(
&self,
request: TablesRequest,
options: CallOptions,
) -> Result<UnaryResponse<OwnedView<TablesResponseView<'static>>>, ConnectError>
pub async fn tables_with_options( &self, request: TablesRequest, options: CallOptions, ) -> Result<UnaryResponse<OwnedView<TablesResponseView<'static>>>, ConnectError>
Call the Tables RPC with explicit per-call options. Options override ClientConfig defaults.
Trait Implementations§
Source§impl<T: Clone> Clone for ServiceClient<T>
impl<T: Clone> Clone for ServiceClient<T>
Source§fn clone(&self) -> ServiceClient<T>
fn clone(&self) -> ServiceClient<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<T> !Freeze for ServiceClient<T>
impl<T> !RefUnwindSafe for ServiceClient<T>
impl<T> Send for ServiceClient<T>where
T: Send,
impl<T> Sync for ServiceClient<T>where
T: Sync,
impl<T> Unpin for ServiceClient<T>where
T: Unpin,
impl<T> UnsafeUnpin for ServiceClient<T>where
T: UnsafeUnpin,
impl<T> !UnwindSafe for ServiceClient<T>
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> 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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more