pub struct ProxyRotator { /* private fields */ }Expand description
Thread-safe proxy rotator that cycles through a list of proxies using a configurable strategy.
The rotator holds a Mutex-protected index that advances each time get_proxy()
is called. Duplicate proxies are rejected at construction time to prevent wasted cycles.
The default strategy is cyclic_rotation, but you can supply any function matching
the RotationStrategy signature.
Implementations§
Source§impl ProxyRotator
impl ProxyRotator
Sourcepub fn new(proxies: Vec<Proxy>) -> Result<Self>
pub fn new(proxies: Vec<Proxy>) -> Result<Self>
Creates a new rotator with the default cyclic_rotation strategy. Returns
an error if the proxy list is empty or contains duplicates.
Sourcepub fn with_strategy(
proxies: Vec<Proxy>,
strategy: RotationStrategy,
) -> Result<Self>
pub fn with_strategy( proxies: Vec<Proxy>, strategy: RotationStrategy, ) -> Result<Self>
Creates a new rotator with a custom rotation strategy. The strategy function receives the full proxy list and the current index, and returns the next index. Returns an error if the proxy list is empty or contains duplicates.
Sourcepub fn get_proxy(&self) -> Proxy
pub fn get_proxy(&self) -> Proxy
Returns the next proxy according to the rotation strategy and advances the internal index. The index is taken modulo the proxy count, so strategies can return any value without worrying about bounds.
Sourcepub fn proxies(&self) -> &[Proxy]
pub fn proxies(&self) -> &[Proxy]
Returns a slice of all configured proxies. Useful for logging or diagnostics.
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