#[non_exhaustive]pub struct CallOptions { /* private fields */ }Expand description
Per-request options for an RPC call.
Provides per-call configuration such as additional headers and timeouts.
Use CallOptions::default() for no additional options.
CallOptions is #[non_exhaustive]: new fields may be added in minor
releases. Construct with CallOptions::default() and the with_*
builder methods, then read settings back through the accessor methods.
§Example
use connectrpc::client::CallOptions;
use std::time::Duration;
let options = CallOptions::default()
.with_timeout(Duration::from_secs(5))
.with_header("x-request-id", "abc123");
assert_eq!(options.timeout(), Some(Duration::from_secs(5)));
assert_eq!(options.headers().get("x-request-id").unwrap(), "abc123");Implementations§
Source§impl CallOptions
impl CallOptions
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
Set the request timeout.
Read via Self::timeout.
Sourcepub fn with_header(
self,
name: impl TryInto<HeaderName>,
value: impl TryInto<HeaderValue>,
) -> Self
pub fn with_header( self, name: impl TryInto<HeaderName>, value: impl TryInto<HeaderValue>, ) -> Self
Add a request header.
If the name or value cannot be converted to valid HTTP header components,
the header is silently ignored. Use try_with_header
for fallible insertion.
Read via Self::headers.
Sourcepub fn try_with_header(
self,
name: impl TryInto<HeaderName>,
value: impl TryInto<HeaderValue>,
) -> Result<Self, ConnectError>
pub fn try_with_header( self, name: impl TryInto<HeaderName>, value: impl TryInto<HeaderValue>, ) -> Result<Self, ConnectError>
Add a request header, returning an error if the name or value is invalid.
Read via Self::headers.
§Errors
Returns ErrorCode::Internal if the name or value cannot be
converted to a valid HTTP header component.
Sourcepub fn with_headers(
self,
headers: impl IntoIterator<Item = (HeaderName, HeaderValue)>,
) -> Self
pub fn with_headers( self, headers: impl IntoIterator<Item = (HeaderName, HeaderValue)>, ) -> Self
Add multiple request headers from an iterator.
Read via Self::headers.
Sourcepub fn with_max_message_size(self, size: usize) -> Self
pub fn with_max_message_size(self, size: usize) -> Self
Set the maximum decompressed message size in bytes.
Read via Self::max_message_size.
Sourcepub fn with_compress(self, enabled: bool) -> Self
pub fn with_compress(self, enabled: bool) -> Self
Override compression for this call. Some(true) forces compression,
Some(false) disables it; not calling this defers to the configured
CompressionPolicy.
Read via Self::compress.
Sourcepub fn headers(&self) -> &HeaderMap
pub fn headers(&self) -> &HeaderMap
Additional headers to include in the request.
These are merged into the HTTP request after protocol headers, allowing override of any header for advanced use cases.
Set via Self::with_header / Self::with_headers.
Sourcepub fn timeout(&self) -> Option<Duration>
pub fn timeout(&self) -> Option<Duration>
The request timeout, sent as connect-timeout-ms / grpc-timeout.
Set via Self::with_timeout.
Sourcepub fn max_message_size(&self) -> Option<usize>
pub fn max_message_size(&self) -> Option<usize>
The maximum decompressed message size in bytes.
When set, messages exceeding this size after decompression will
result in a ResourceExhausted error. Applies per-message for streaming.
Set via Self::with_max_message_size.
Sourcepub fn compress(&self) -> Option<bool>
pub fn compress(&self) -> Option<bool>
The per-call compression override. Some(true) forces compression,
Some(false) disables it, None defers to the policy.
Set via Self::with_compress.
Trait Implementations§
Source§impl Clone for CallOptions
impl Clone for CallOptions
Source§fn clone(&self) -> CallOptions
fn clone(&self) -> CallOptions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more