pub struct ProxyRotator { /* private fields */ }Expand description
A pool of validated proxies plus a selection strategy.
Construct via ProxyRotator::build. Returns Ok(None) when there are no
proxies (caller then connects directly, preserving today’s behaviour).
Implementations§
Source§impl ProxyRotator
impl ProxyRotator
Sourcepub fn build(
list: &[String],
single: Option<&str>,
strategy: ProxyRotation,
) -> Result<Option<Self>, String>
pub fn build( list: &[String], single: Option<&str>, strategy: ProxyRotation, ) -> Result<Option<Self>, String>
Build a rotator with precedence: a non-empty list wins; otherwise the
single single proxy becomes a pool of one; otherwise Ok(None).
Every entry is validated — any malformed URL is a hard error (no silent
no-proxy fallback). The error is a human-readable string the caller maps
to a crate::CrwError.
Sourcepub fn pick(&self, host_key: Option<&str>) -> &ProxyEntry
pub fn pick(&self, host_key: Option<&str>) -> &ProxyEntry
Select a proxy for a request. host_key is used only by
ProxyRotation::StickyPerHost; pass the normalized target host.
Sourcepub fn pick_index(&self, host_key: Option<&str>) -> usize
pub fn pick_index(&self, host_key: Option<&str>) -> usize
Index into the validated pool for this request, applying the strategy.
StickyPerHost is stateless: the index is a deterministic hash of the
host modulo the pool size. This keeps a host pinned to one proxy for the
rotator’s lifetime with no per-host map (no unbounded growth, no lock, and
— crucially — no cursor side-effect, so repeated picks for the same host
are idempotent and HTTP + CDP always agree).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ProxyRotator
impl RefUnwindSafe for ProxyRotator
impl Send for ProxyRotator
impl Sync for ProxyRotator
impl Unpin for ProxyRotator
impl UnsafeUnpin for ProxyRotator
impl UnwindSafe for ProxyRotator
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> 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