Function record_timestamp_with_cleanup

Source
pub fn record_timestamp_with_cleanup(
    timestamps: &mut Vec<Instant>,
    timestamp: Instant,
    window_duration: Duration,
    max_capacity: Option<usize>,
    auto_cleanup: bool,
) -> usize
Expand description

Record a new timestamp and perform cleanup if needed

This function adds a new timestamp to the collection and optionally performs cleanup of old timestamps to maintain memory efficiency.

§Arguments

  • timestamps - Mutable reference to a vector of timestamps
  • timestamp - The new timestamp to record
  • window_duration - Duration of the rate limiting window
  • max_capacity - Optional maximum capacity for the timestamp vector
  • auto_cleanup - Whether to automatically cleanup old timestamps

§Returns

The number of timestamps that were cleaned up (if any)