Skip to main content

ClientCore

Struct ClientCore 

Source
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

Source

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.

Source

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).

Source

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.

Source

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.

Source

pub fn config(&self) -> &ClientConfig

The retention/config settings.

Source

pub fn config_mut(&mut self) -> &mut ClientConfig

Mutably borrow the retention/config settings.

Source

pub fn options(&self) -> &RequestOptions

The options every request this core sends carries (the default ones until Self::set_options replaces them).

Source

pub fn set_options(&mut self, options: RequestOptions)

Replace the options every later request this core sends carries.

Source

pub fn base_url(&self) -> &Url

The base URL.

Source

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.

Source

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.

Source

pub fn set_credential(&mut self, scheme: &str, credential: Credential)

Register a credential for a named security scheme, replacing any already registered for it.

Source

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.

Source

pub fn credential(&self, scheme: &str) -> Option<&Credential>

Retrieve a registered credential by scheme name.

Source

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.

Source

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.

Source

pub fn bound_header(&self, name: &str) -> Option<&str>

The value bound to the header name, matched in any letter case.

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

Source§

fn clone(&self) -> ClientCore

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

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.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>
where T: Sized,

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
§

unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ

Consume a handle, getting back the initial Arc<> Read more
§

unsafe fn get_arc(handle: Handle) -> Arc<Self> ⓘ

Get a clone of the Arc<> using a “borrowed” handle. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> MaybeSync for T
where T: Sync + ?Sized,

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more