Skip to main content

parse_rate_limit_headers

Function parse_rate_limit_headers 

Source
pub fn parse_rate_limit_headers<S>(
    headers: &HashMap<String, String, S>,
) -> Vec<RestApiRateLimit>
where S: BuildHasher,
Expand description

Parses rate limit headers from a HashMap of headers and returns a vector of RestApiRateLimit.

This function extracts rate limit information from headers with specific patterns (x-mbx-used-weight or x-mbx-order-count) and converts them into RestApiRateLimit structures. It handles different intervals (seconds, minutes, hours, days) and distinguishes between request weight and order rate limits.

§Arguments

  • headers - A reference to a HashMap containing HTTP headers

§Returns

A Vec<RestApiRateLimit> containing parsed rate limit information

§Panics

  • If the static regex fails to compile (via Regex::new(...).unwrap()), which can only happen if the literal pattern is invalid.
  • If a matching header’s key doesn’t actually contain both capture groups (so caps.get(2).unwrap() or caps.get(3).unwrap() fails).

§Examples

let headers: HashMap<String, String> = // … headers with rate limit information let rate_limits = parse_rate_limit_headers(&headers);