1
0
mirror of https://github.com/actix/examples synced 2025-06-26 17:17:42 +02:00

chore: address deprecations

This commit is contained in:
Rob Ede
2024-03-11 19:47:15 +00:00
parent cccda67c1e
commit 327cc9a549
3 changed files with 15 additions and 13 deletions

View File

@ -11,8 +11,8 @@ use actix_web::{
dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform},
Error, HttpResponse,
};
use chrono::{Local, NaiveDateTime};
use futures_util::{future::LocalBoxFuture, FutureExt, TryFutureExt};
use chrono::{DateTime, Utc};
use futures_util::{future::LocalBoxFuture, FutureExt as _, TryFutureExt as _};
#[doc(hidden)]
pub struct RateLimitService<S> {
@ -95,7 +95,7 @@ struct TokenBucket {
capacity: u64,
/// Time that last request was accepted.
last_req_time: NaiveDateTime,
last_req_time: DateTime<Utc>,
/// Numbers of tokens remaining.
///
@ -108,7 +108,7 @@ impl TokenBucket {
fn new(limit: u64) -> Self {
TokenBucket {
limit,
last_req_time: NaiveDateTime::UNIX_EPOCH,
last_req_time: DateTime::<Utc>::UNIX_EPOCH,
capacity: limit,
tokens: 0,
}
@ -116,7 +116,7 @@ impl TokenBucket {
/// Mutates leaky bucket for accepted request.
fn allow_query(&mut self) -> bool {
let current_time = Local::now().naive_local();
let current_time = Utc::now();
let time_elapsed = (current_time.timestamp() - self.last_req_time.timestamp()) as u64;