4444//! trait and provides an *event-handler* as part of its API. This *event-handler*
4545//! needs to be called by the user on every event on the rate limiter's `AsRawFd` FD.
4646
47- use std:: io;
4847use std:: os:: unix:: io:: { AsRawFd , RawFd } ;
4948use std:: sync:: Mutex ;
5049use std:: sync:: atomic:: { AtomicBool , Ordering } ;
5150use std:: time:: { Duration , Instant } ;
51+ use std:: { cmp, io} ;
5252
5353use log:: error;
5454use thiserror:: Error ;
@@ -65,7 +65,7 @@ pub enum Error {
6565 SpuriousRateLimiterEvent ( & ' static str ) ,
6666 /// The event handler encounters while TimerFd::wait()
6767 #[ error( "Failed to wait for the timer" ) ]
68- TimerFdWaitError ( #[ source] std :: io:: Error ) ,
68+ TimerFdWaitError ( #[ source] io:: Error ) ,
6969}
7070
7171// Interval at which the refill timer will run when limiter is at capacity.
@@ -220,7 +220,7 @@ impl TokenBucket {
220220 self . one_time_burst += tokens;
221221 return ;
222222 }
223- self . budget = std :: cmp:: min ( self . budget + tokens, self . size ) ;
223+ self . budget = cmp:: min ( self . budget + tokens, self . size ) ;
224224 }
225225
226226 /// Returns the capacity of the token bucket.
@@ -359,7 +359,7 @@ impl RateLimiter {
359359 libc:: fcntl ( fd, libc:: F_SETFL , flags)
360360 } ;
361361 if ret < 0 {
362- return Err ( std :: io:: Error :: last_os_error ( ) ) ;
362+ return Err ( io:: Error :: last_os_error ( ) ) ;
363363 }
364364
365365 Ok ( RateLimiter {
@@ -463,10 +463,10 @@ impl RateLimiter {
463463 // `timer_fd::wait()` won't block (which is different from its default behavior.)
464464 match guard. timer_fd . wait ( ) {
465465 Err ( e) => {
466- let err: std :: io:: Error = e. into ( ) ;
466+ let err: io:: Error = e. into ( ) ;
467467 match err. kind ( ) {
468- std :: io:: ErrorKind :: Interrupted => ( ) ,
469- std :: io:: ErrorKind :: WouldBlock => {
468+ io:: ErrorKind :: Interrupted => ( ) ,
469+ io:: ErrorKind :: WouldBlock => {
470470 return Err ( Error :: SpuriousRateLimiterEvent (
471471 "Rate limiter event handler called without a present timer" ,
472472 ) ) ;
0 commit comments