Skip to content

Commit fffa200

Browse files
htonkovacrbradford
authored andcommitted
rate_limiter: trim qualified paths
Import the std modules used in the crate instead of spelling the full paths at every use site. Signed-off-by: Henry Hrvoje Tonkovac <htonkovac@gmail.com> Assisted-by: Claude:Opus-4.8
1 parent 0e4e327 commit fffa200

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

rate_limiter/src/group.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use core::panic::AssertUnwindSafe;
88
use std::fs::File;
99
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
1010
use std::sync::{Arc, Mutex};
11-
use std::{io, result, thread};
11+
use std::{io, panic, result, thread};
1212

1313
use log::{error, info, warn};
1414
use thiserror::Error;
@@ -222,7 +222,7 @@ impl RateLimiterGroup {
222222
thread::Builder::new()
223223
.name(format!("rate-limit-group-{}", inner.id))
224224
.spawn(move || {
225-
let res = std::panic::catch_unwind(AssertUnwindSafe(move || {
225+
let res = panic::catch_unwind(AssertUnwindSafe(move || {
226226
const EPOLL_EVENTS_LEN: usize = 2;
227227

228228
let mut events =

rate_limiter/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
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;
4847
use std::os::unix::io::{AsRawFd, RawFd};
4948
use std::sync::Mutex;
5049
use std::sync::atomic::{AtomicBool, Ordering};
5150
use std::time::{Duration, Instant};
51+
use std::{cmp, io};
5252

5353
use log::error;
5454
use 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

Comments
 (0)