pub struct Builder<Tls = TlsUnset> { /* private fields */ }default-client only.Expand description
Builds a partition-aware connection pool.
Implementations§
Source§impl<Tls> Builder<Tls>
impl<Tls> Builder<Tls>
Sourcepub fn idle_timeout(self, timeout: impl Into<Option<Duration>>) -> Self
pub fn idle_timeout(self, timeout: impl Into<Option<Duration>>) -> Self
Sets how long a reusable idle connection remains in the pool.
Passing None disables idle expiration. When unset, the pool uses a
90-second timeout.
Sourcepub fn set_idle_timeout(
&mut self,
timeout: Option<Option<Duration>>,
) -> &mut Self
pub fn set_idle_timeout( &mut self, timeout: Option<Option<Duration>>, ) -> &mut Self
Mutably sets the idle timeout.
The outer None restores the default; Some(None) disables expiry.
Sourcepub fn time_source(self, source: impl TimeSource + 'static) -> Self
pub fn time_source(self, source: impl TimeSource + 'static) -> Self
Sets the clock used by pool maintenance and connection timing.
Sourcepub fn set_time_source(&mut self, source: Option<SharedTimeSource>) -> &mut Self
pub fn set_time_source(&mut self, source: Option<SharedTimeSource>) -> &mut Self
Mutably sets the clock used by pool maintenance and connection timing.
Sourcepub fn sleep_impl(self, sleep: impl AsyncSleep + 'static) -> Self
pub fn sleep_impl(self, sleep: impl AsyncSleep + 'static) -> Self
Sets the sleep implementation used by pool maintenance.
Sourcepub fn set_sleep_impl(&mut self, sleep: Option<SharedAsyncSleep>) -> &mut Self
pub fn set_sleep_impl(&mut self, sleep: Option<SharedAsyncSleep>) -> &mut Self
Mutably sets the sleep implementation used by pool maintenance.
Sourcepub fn tcp_nodelay(self, enabled: bool) -> Self
pub fn tcp_nodelay(self, enabled: bool) -> Self
Configures TCP_NODELAY for newly created sockets.
Sourcepub fn set_tcp_nodelay(&mut self, enabled: bool) -> &mut Self
pub fn set_tcp_nodelay(&mut self, enabled: bool) -> &mut Self
Mutably configures TCP_NODELAY.
Sourcepub fn tcp_keepalive(self, time: impl Into<Option<Duration>>) -> Self
pub fn tcp_keepalive(self, time: impl Into<Option<Duration>>) -> Self
Configures TCP keepalive for newly created sockets.
Sourcepub fn set_tcp_keepalive(&mut self, time: Option<Option<Duration>>) -> &mut Self
pub fn set_tcp_keepalive(&mut self, time: Option<Option<Duration>>) -> &mut Self
Mutably configures TCP keepalive.
Sourcepub fn max_connections_per_host(self, limit: usize) -> Self
pub fn max_connections_per_host(self, limit: usize) -> Self
Bounds connection capacity for one origin across every pool partition.
An origin is a scheme, host, and port, so https://example.com and
http://example.com are bounded separately, as is each non-default
port. Establishing, idle, and active connections occupy capacity.
Logical close normally returns capacity while accepted work drains.
An HTTP/1 upgrade retains capacity until the caller releases upgraded
I/O. This is not an idle-connection limit.
Sourcepub fn set_max_connections_per_host(
&mut self,
limit: Option<usize>,
) -> &mut Self
pub fn set_max_connections_per_host( &mut self, limit: Option<usize>, ) -> &mut Self
Mutably sets the connection-capacity bound described by
Builder::max_connections_per_host.
Sourcepub fn connection_reuse_scope(self, scope: ConnectionReuseScope) -> Self
pub fn connection_reuse_scope(self, scope: ConnectionReuseScope) -> Self
Selects which partitions may reuse each other’s connections.
Sourcepub fn set_connection_reuse_scope(
&mut self,
scope: ConnectionReuseScope,
) -> &mut Self
pub fn set_connection_reuse_scope( &mut self, scope: ConnectionReuseScope, ) -> &mut Self
Mutably selects the connection reuse scope.
Sourcepub fn has_explicit_partitions(&self) -> bool
pub fn has_explicit_partitions(&self) -> bool
Returns whether an explicit partition set is configured.
An explicitly supplied empty set also returns true. Clearing the set
with Self::set_partitions and None restores anonymous partition
construction.
Sourcepub fn partitions(self, partitions: impl IntoIterator<Item = Partition>) -> Self
pub fn partitions(self, partitions: impl IntoIterator<Item = Partition>) -> Self
Declares the complete explicit partition set.
Sourcepub fn set_partitions(
&mut self,
partitions: Option<Vec<Partition>>,
) -> &mut Self
pub fn set_partitions( &mut self, partitions: Option<Vec<Partition>>, ) -> &mut Self
Mutably declares or clears the explicit partition set.
Sourcepub fn proxy_config(self, config: ProxyConfig) -> Self
pub fn proxy_config(self, config: ProxyConfig) -> Self
Configures proxy selection for every connection established by this pool.
The configuration applies across every partition. Proxying is disabled unless this method is called.
Sourcepub fn set_proxy_config(&mut self, config: Option<ProxyConfig>) -> &mut Self
pub fn set_proxy_config(&mut self, config: Option<ProxyConfig>) -> &mut Self
Mutably configures pool-wide proxy selection.
Passing None disables proxying.
Sourcepub fn dns_resolver(self, resolver: impl ResolveDns + 'static) -> Self
pub fn dns_resolver(self, resolver: impl ResolveDns + 'static) -> Self
Configures the DNS resolver used by connections established by this pool.
The resolver applies across every partition. When unset, the client uses its default resolver, which currently delegates to the operating system.
Examples found in repository?
23fn main() {
24 let _legacy_client = Builder::new()
25 .tls_provider(tls::Provider::Rustls(CryptoMode::Ring))
26 .build_with_resolver(StaticResolver);
27
28 let pool = ConnectionPool::builder()
29 .dns_resolver(StaticResolver)
30 .tls_provider(tls::Provider::Rustls(CryptoMode::Ring))
31 .build_https()
32 .expect("valid connection pool");
33 let _partitioned_client =
34 PoolClient::new(&pool).expect("pool contains the anonymous partition");
35}Sourcepub fn set_dns_resolver(
&mut self,
resolver: Option<SharedDnsResolver>,
) -> &mut Self
pub fn set_dns_resolver( &mut self, resolver: Option<SharedDnsResolver>, ) -> &mut Self
Mutably configures the pool-wide DNS resolver.
Passing None restores the client default.
Sourcepub fn event_listener(self, listener: impl ConnectionEventListener) -> Self
pub fn event_listener(self, listener: impl ConnectionEventListener) -> Self
Observes connection establishment and installed-lifetime transitions.
The listener applies to every partition. Each callback runs synchronously on the task that completed the transition and after pool locks are released. A listener must not block on work that requires progress from that same task.
Observation is disabled unless a listener is configured.
Sourcepub fn set_event_listener(
&mut self,
listener: Option<SharedConnectionEventListener>,
) -> &mut Self
pub fn set_event_listener( &mut self, listener: Option<SharedConnectionEventListener>, ) -> &mut Self
Mutably configures pool-wide connection lifecycle observation.
Passing None disables observation. The callback contract is the same
as Builder::event_listener.
Source§impl Builder<TlsUnset>
impl Builder<TlsUnset>
Sourcepub fn tls_provider(self, provider: Provider) -> Builder<TlsProviderSelected>
pub fn tls_provider(self, provider: Provider) -> Builder<TlsProviderSelected>
Selects the TLS provider used by HTTPS pool connections.
Examples found in repository?
23fn main() {
24 let _legacy_client = Builder::new()
25 .tls_provider(tls::Provider::Rustls(CryptoMode::Ring))
26 .build_with_resolver(StaticResolver);
27
28 let pool = ConnectionPool::builder()
29 .dns_resolver(StaticResolver)
30 .tls_provider(tls::Provider::Rustls(CryptoMode::Ring))
31 .build_https()
32 .expect("valid connection pool");
33 let _partitioned_client =
34 PoolClient::new(&pool).expect("pool contains the anonymous partition");
35}Source§impl Builder<TlsProviderSelected>
impl Builder<TlsProviderSelected>
Sourcepub fn build_https(self) -> Result<ConnectionPool, BuildError>
pub fn build_https(self) -> Result<ConnectionPool, BuildError>
Builds a pool whose connector performs TLS and ALPN negotiation.
Examples found in repository?
23fn main() {
24 let _legacy_client = Builder::new()
25 .tls_provider(tls::Provider::Rustls(CryptoMode::Ring))
26 .build_with_resolver(StaticResolver);
27
28 let pool = ConnectionPool::builder()
29 .dns_resolver(StaticResolver)
30 .tls_provider(tls::Provider::Rustls(CryptoMode::Ring))
31 .build_https()
32 .expect("valid connection pool");
33 let _partitioned_client =
34 PoolClient::new(&pool).expect("pool contains the anonymous partition");
35}Source§impl Builder<TlsProviderSelected>
impl Builder<TlsProviderSelected>
Sourcepub fn tls_context(self, context: TlsContext) -> Self
Available on crate features __rustls or s2n-tls only.
pub fn tls_context(self, context: TlsContext) -> Self
__rustls or s2n-tls only.Sets provider-specific TLS configuration for HTTPS connections.
Sourcepub fn set_tls_context(&mut self, context: TlsContext) -> &mut Self
Available on crate features __rustls or s2n-tls only.
pub fn set_tls_context(&mut self, context: TlsContext) -> &mut Self
__rustls or s2n-tls only.Mutably sets provider-specific TLS configuration.
Trait Implementations§
Auto Trait Implementations§
impl<Tls = TlsUnset> !Freeze for Builder<Tls>
impl<Tls = TlsUnset> !RefUnwindSafe for Builder<Tls>
impl<Tls = TlsUnset> !UnwindSafe for Builder<Tls>
impl<Tls> Send for Builder<Tls>where
Tls: Send,
impl<Tls> Sync for Builder<Tls>where
Tls: Sync,
impl<Tls> Unpin for Builder<Tls>where
Tls: Unpin,
impl<Tls> UnsafeUnpin for Builder<Tls>where
Tls: UnsafeUnpin,
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,
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 moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);