pub struct RateLimit { /* private fields */ }Expand description
Ограничение частоты запросов.
Хранит минимальный интервал между последовательными запросами.
Implementations§
Source§impl RateLimit
impl RateLimit
Sourcepub fn every(min_interval: Duration) -> Self
pub fn every(min_interval: Duration) -> Self
Создать limit из минимального интервала между запросами.
Examples found in repository?
examples/actual_indexes_dump.rs (line 43)
39fn main() -> Result<(), ExampleError> {
40 let moex_client = Client::builder()
41 .user_agent_from_crate()
42 .timeout(Duration::from_secs(REQUEST_TIMEOUT_SECS))
43 .rate_limit(RateLimit::every(Duration::from_millis(RATE_LIMIT_MILLIS)))
44 .metadata(false)
45 .build()?;
46
47 println!("loading active indexes...");
48 let index_dumps = load_actual_index_dumps(&moex_client)?;
49 println!("active indexes loaded: {}", index_dumps.len());
50
51 let wanted_secids = collect_unique_secids(&index_dumps);
52 println!(
53 "resolving snapshots for {} unique securities...",
54 wanted_secids.len()
55 );
56 let (snapshots, missing_mapping) = load_security_snapshots(&moex_client, &wanted_secids)?;
57 println!(
58 "resolved snapshots: {}, missing: {}",
59 snapshots.len(),
60 missing_mapping.len()
61 );
62
63 print_dump(&index_dumps, &snapshots, &missing_mapping);
64 Ok(())
65}Sourcepub fn per_second(requests_per_second: NonZeroU32) -> Self
pub fn per_second(requests_per_second: NonZeroU32) -> Self
Создать limit из числа запросов в секунду.
Интервал округляется вверх до целого числа наносекунд.
Sourcepub fn min_interval(self) -> Duration
pub fn min_interval(self) -> Duration
Минимальный интервал между запросами.
Trait Implementations§
impl Copy for RateLimit
impl Eq for RateLimit
impl StructuralPartialEq for RateLimit
Auto Trait Implementations§
impl Freeze for RateLimit
impl RefUnwindSafe for RateLimit
impl Send for RateLimit
impl Sync for RateLimit
impl Unpin for RateLimit
impl UnsafeUnpin for RateLimit
impl UnwindSafe for RateLimit
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