pub struct ClientCore { /* private fields */ }Expand description
The shared core every generated Client wraps: the swappable transport HttpBackend that
executes requests, the base URL, configuration, and per-scheme credentials.
Requests are built by the runtime itself, as an http::Request, whichever backend executes
them; the runtime’s send hands each one to the backend. new/with_config install the
default ReqwestBackend on a reqwest::Client built from the configuration,
with_client installs one on a caller-supplied reqwest::Client, and with_backend plugs a
caller-supplied transport.
The generated Client wraps one of these and documents its own constructors; each of its
operation methods delegates to the shared dispatch routines.
Implementations§
Source§impl ClientCore
impl ClientCore
Sourcepub fn new(base_url: &str) -> Result<Self, Error<Infallible>>
pub fn new(base_url: &str) -> Result<Self, Error<Infallible>>
Build a core with the default ClientConfig and TransportConfig and the given base
URL, as Self::with_config does.
Sourcepub fn with_config(
base_url: &str,
config: ClientConfig,
transport: TransportConfig,
) -> Result<Self, Error<Infallible>>
pub fn with_config( base_url: &str, config: ClientConfig, transport: TransportConfig, ) -> Result<Self, Error<Infallible>>
Build a core with the given base URL and configuration, executing requests on the default
ReqwestBackend over a reqwest::Client built from transport’s
connect and read
timeouts. Returns a request-construction error if the base URL is not an http or https
URL, or reqwest cannot build the client (its TLS backend fails to initialise).
Sourcepub fn with_client(
client: Client,
base_url: &str,
) -> Result<Self, Error<Infallible>>
pub fn with_client( client: Client, base_url: &str, ) -> Result<Self, Error<Infallible>>
Build a core executing requests on a caller-supplied reqwest::Client — the injection
point for TLS backend, proxies, and timeouts — wrapped in the default ReqwestBackend,
as Self::with_backend would with Arc::new(ReqwestBackend::new(client)). The client’s
own connect and read timeouts apply, and no TransportConfig is read;
ClientConfig::timeout still applies to each request the runtime’s send sends.
The client keeps its own redirect policy too, not the same-origin one TransportConfig
describes: under reqwest’s default it follows a redirect to any origin, and every header
reqwest does not strip on a cross-origin hop (an apiKey header, a bound header, a
RequestOptions::headers entry) travels with it.
Sourcepub fn with_backend(
backend: Arc<dyn HttpBackend>,
base_url: &str,
) -> Result<Self, Error<Infallible>>
pub fn with_backend( backend: Arc<dyn HttpBackend>, base_url: &str, ) -> Result<Self, Error<Infallible>>
Build a core with a caller-supplied transport HttpBackend — the injection point for
retry, middleware, or an entirely non-reqwest transport — and the default
ClientConfig; nothing else is built, so several cores can share one backend. Every
request is executed by backend, so connecting and reading are bounded however backend
bounds them. ClientConfig::timeout travels on each request the runtime’s send sends,
as a super::TotalTimeout extension, for backend to enforce. Redirects are followed,
or not, as backend decides, not by the same-origin policy TransportConfig describes.
Returns a request-construction error if the base URL is not an http or https URL.
Sourcepub fn config(&self) -> &ClientConfig
pub fn config(&self) -> &ClientConfig
The retention/config settings.
Sourcepub fn config_mut(&mut self) -> &mut ClientConfig
pub fn config_mut(&mut self) -> &mut ClientConfig
Mutably borrow the retention/config settings.
Sourcepub fn options(&self) -> &RequestOptions
pub fn options(&self) -> &RequestOptions
The options every request this core sends carries (the default ones until
Self::set_options replaces them).
Sourcepub fn set_options(&mut self, options: RequestOptions)
pub fn set_options(&mut self, options: RequestOptions)
Replace the options every later request this core sends carries.
Sourcepub fn set_base_url(&mut self, base_url: &str) -> Result<(), Error<Infallible>>
pub fn set_base_url(&mut self, base_url: &str) -> Result<(), Error<Infallible>>
Replace the base URL every later request is resolved against, keeping the backend,
configuration and credentials. Returns a request-construction error, leaving the base URL
as it was, if base_url is not an http or https URL.
Sourcepub fn backend(&self) -> &Arc<dyn HttpBackend> ⓘ
pub fn backend(&self) -> &Arc<dyn HttpBackend> ⓘ
The transport backend that executes requests. The runtime’s send dispatches through this;
retry/middleware layers can clone the Arc to wrap it.
Sourcepub fn set_credential(&mut self, scheme: &str, credential: Credential)
pub fn set_credential(&mut self, scheme: &str, credential: Credential)
Register a credential for a named security scheme, replacing any already registered for it.
Sourcepub fn remove_credential(&mut self, scheme: &str) -> Option<Credential>
pub fn remove_credential(&mut self, scheme: &str) -> Option<Credential>
Unregister the credential for a named security scheme, returning it if one was registered.
This is how a caller reaches a later security alternative: an operation attaches the first
non-empty alternative whose schemes all have a registered credential, so removing a scheme
of an earlier one lets the next call pass over it. Removing a scheme that was never
registered is a no-op returning None.
Sourcepub fn credential(&self, scheme: &str) -> Option<&Credential>
pub fn credential(&self, scheme: &str) -> Option<&Credential>
Retrieve a registered credential by scheme name.
Sourcepub fn bind_header(
&mut self,
name: &str,
value: impl Into<String>,
) -> Result<(), Error<Infallible>>
pub fn bind_header( &mut self, name: &str, value: impl Into<String>, ) -> Result<(), Error<Infallible>>
Bind value to the header name, matched in any letter case, replacing any value already
bound to it. An operation of a generated client whose header parameter the build bound
(Spec::add_bound_header) sends this value, as written, instead of taking an argument for
it. ClientCore’s Debug prints the bound name and redacts the value, and the operation
sends it marked sensitive (HeaderValue::set_sensitive), so the request’s Debug redacts
it too.
Returns a request-construction error, binding nothing and leaving any value already bound
in place, if name is not a valid header name (an empty name, or one holding a space, a
colon, a control character or a byte past ASCII), or if value is not a valid header
value: it holds a control character other than a tab, such as CR, LF, NUL or DEL. The
error names the header and does not quote the value.
Sourcepub fn unbind_header(&mut self, name: &str) -> Option<SecretString>
pub fn unbind_header(&mut self, name: &str) -> Option<SecretString>
Unbind the header name, matched in any letter case, returning the value bound to it if
there was one, as the secret the core held it as, so its Debug redacts it. An operation
that requires the header then fails with super::RequestError::MissingBoundParameter
before anything is sent.
Sourcepub fn bound_header(&self, name: &str) -> Option<&str>
pub fn bound_header(&self, name: &str) -> Option<&str>
The value bound to the header name, matched in any letter case.
Sourcepub fn paginate_links<T>(&self, first: Url) -> LinkPaginator<T>
pub fn paginate_links<T>(&self, first: Url) -> LinkPaginator<T>
Start a LinkPaginator<T> over a Link-header-paginated collection, beginning at first.
See the paginate module’s docs for the full pattern and the authentication caveat.
Trait Implementations§
Source§impl Clone for ClientCore
impl Clone for ClientCore
Source§fn clone(&self) -> ClientCore
fn clone(&self) -> ClientCore
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ClientCore
Prints the base URL without its userinfo and query, the two places a URL carries a credential
(a user:password@ prefix the request builder sends as Authorization: Basic, an apiKey
query parameter); ClientCore::base_url returns it as configured.
impl Debug for ClientCore
Prints the base URL without its userinfo and query, the two places a URL carries a credential
(a user:password@ prefix the request builder sends as Authorization: Basic, an apiKey
query parameter); ClientCore::base_url returns it as configured.
Auto Trait Implementations§
impl !RefUnwindSafe for ClientCore
impl !UnwindSafe for ClientCore
impl Freeze for ClientCore
impl Send for ClientCore
impl Sync for ClientCore
impl Unpin for ClientCore
impl UnsafeUnpin for ClientCore
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
Arc<> Read more§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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