1
0
mirror of https://github.com/actix/examples synced 2024-11-23 14:31:07 +01:00

chore: address deprecations

This commit is contained in:
Rob Ede 2024-03-11 19:47:15 +00:00
parent cccda67c1e
commit 327cc9a549
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
3 changed files with 15 additions and 13 deletions

View File

@ -1,7 +1,9 @@
#![allow(clippy::extra_unused_lifetimes)]
use chrono::{NaiveDateTime, TimeDelta, Utc};
use diesel::{r2d2::ConnectionManager, PgConnection};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::schema::*;
@ -13,7 +15,7 @@ pub type Pool = r2d2::Pool<ConnectionManager<PgConnection>>;
pub struct User {
pub email: String,
pub hash: String,
pub created_at: chrono::NaiveDateTime,
pub created_at: NaiveDateTime,
}
impl User {
@ -29,9 +31,9 @@ impl User {
#[derive(Debug, Serialize, Deserialize, Queryable, Insertable)]
#[diesel(table_name = invitations)]
pub struct Invitation {
pub id: uuid::Uuid,
pub id: Uuid,
pub email: String,
pub expires_at: chrono::NaiveDateTime,
pub expires_at: NaiveDateTime,
}
// any type that implements Into<String> can be used to create Invitation
@ -41,9 +43,9 @@ where
{
fn from(email: T) -> Self {
Invitation {
id: uuid::Uuid::new_v4(),
id: Uuid::new_v4(),
email: email.into(),
expires_at: chrono::Local::now().naive_local() + chrono::Duration::hours(24),
expires_at: (Utc::now() + TimeDelta::try_hours(24).unwrap()).naive_utc(),
}
}
}

View File

@ -4,7 +4,7 @@ use actix_web::{
HttpResponse, Responder,
};
use apalis::{prelude::*, redis::RedisStorage};
use chrono::{Duration, Utc};
use chrono::{TimeDelta, Utc};
use serde::Deserialize;
use crate::{persistent_jobs::Email, ItemCache};
@ -12,7 +12,7 @@ use crate::{persistent_jobs::Email, ItemCache};
#[derive(Debug, Deserialize)]
pub(crate) struct CacheInsert {
data: String,
duration: u64,
duration: u32,
}
#[get("/cache")]
@ -26,7 +26,7 @@ pub(crate) async fn cache_item(
cache: Data<ItemCache>,
web::Json(form): web::Json<CacheInsert>,
) -> actix_web::Result<impl Responder> {
let expires = Utc::now() + Duration::seconds(form.duration as i64);
let expires = Utc::now() + TimeDelta::try_seconds(form.duration as i64).unwrap();
// insert into item cache
cache.lock().unwrap().insert(form.data, expires);

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;