pub struct WeightedStrategy;Expand description
Selects a healthy proxy with probability proportional to its weight.
Proxies with weight == 0 are never selected.
§Example
use stygian_proxy::strategy::{WeightedStrategy, RotationStrategy, ProxyCandidate};
use stygian_proxy::types::ProxyMetrics;
use std::sync::Arc;
use uuid::Uuid;
let strategy = WeightedStrategy;
let candidates = vec![
ProxyCandidate { id: Uuid::new_v4(), weight: 10, metrics: Arc::new(ProxyMetrics::default()), healthy: true },
ProxyCandidate { id: Uuid::new_v4(), weight: 1, metrics: Arc::new(ProxyMetrics::default()), healthy: true },
];
strategy.select(&candidates).await.unwrap();Trait Implementations§
Source§impl Clone for WeightedStrategy
impl Clone for WeightedStrategy
Source§fn clone(&self) -> WeightedStrategy
fn clone(&self) -> WeightedStrategy
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for WeightedStrategy
impl Debug for WeightedStrategy
Source§impl Default for WeightedStrategy
impl Default for WeightedStrategy
Source§fn default() -> WeightedStrategy
fn default() -> WeightedStrategy
Returns the “default value” for a type. Read more
Source§impl RotationStrategy for WeightedStrategy
impl RotationStrategy for WeightedStrategy
Source§fn select<'a, 'life0, 'async_trait>(
&'life0 self,
candidates: &'a [ProxyCandidate],
) -> Pin<Box<dyn Future<Output = ProxyResult<&'a ProxyCandidate>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
fn select<'a, 'life0, 'async_trait>(
&'life0 self,
candidates: &'a [ProxyCandidate],
) -> Pin<Box<dyn Future<Output = ProxyResult<&'a ProxyCandidate>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
Select one candidate from
candidates. Read moreimpl Copy for WeightedStrategy
Auto Trait Implementations§
impl Freeze for WeightedStrategy
impl RefUnwindSafe for WeightedStrategy
impl Send for WeightedStrategy
impl Sync for WeightedStrategy
impl Unpin for WeightedStrategy
impl UnsafeUnpin for WeightedStrategy
impl UnwindSafe for WeightedStrategy
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
Mutably borrows from an owned value. Read more