Replaced async_trait with async in traits from 2024 edition

This commit is contained in:
2025-03-07 22:40:10 +01:00
parent 2f1eb4df3a
commit 5a77407297
16 changed files with 90 additions and 127 deletions

View File

@ -1,14 +1,13 @@
use {
crate::{serde::response::BaseResponse, serde::traits::DeserializeInto},
async_trait::async_trait,
axum::{
Json,
body::to_bytes,
response::{IntoResponse, Response},
Json,
},
serde::{
de::{DeserializeOwned, Error},
Serialize,
de::{DeserializeOwned, Error},
},
};
@ -18,7 +17,6 @@ impl<T: Serialize> IntoResponse for BaseResponse<T> {
}
}
#[async_trait]
impl DeserializeInto for Response {
async fn deserialize_into<T: DeserializeOwned>(self) -> Result<T, serde_json::Error> {
let body = to_bytes(self.into_body(), usize::MAX).await.map_err(|e| {

View File

@ -13,8 +13,8 @@
/// use lib::router;
/// async fn simplify(path: axum::extract::path::Path<String>) {}
/// router!("/simplify", lib::routes!(
/// get "/:exp" => simplify,
/// get "/table/:exp" => || async {}
/// get "/{exp}" => simplify,
/// get "/table/{exp}" => async || {}
/// ));
/// ```
#[macro_export]
@ -92,8 +92,8 @@ macro_rules! join_routes {
#[cfg(test)]
mod tests {
use axum::extract::State;
use axum::Router;
use axum::extract::State;
async fn index() {}

View File

@ -1,17 +1,16 @@
use async_trait::async_trait;
use deadpool_diesel::Status;
use derive_more::From;
use diesel_async::AsyncPgConnection;
use diesel_async::pooled_connection::deadpool::{Object, PoolError};
use lib::diesel::pool::PgPool;
#[async_trait]
pub trait GetConnection: Clone + Send + Sync {
async fn get(&self) -> Result<Object<AsyncPgConnection>, GetConnectionError>;
fn get(
&self,
) -> impl Future<Output = Result<Object<AsyncPgConnection>, GetConnectionError>> + Send;
fn status(&self) -> Status;
}
#[async_trait]
impl GetConnection for PgPool {
async fn get(&self) -> Result<Object<AsyncPgConnection>, GetConnectionError> {
self.get().await.map_err(Into::into)

View File

@ -1,7 +1,7 @@
use async_trait::async_trait;
use serde::de::DeserializeOwned;
#[async_trait]
pub trait DeserializeInto {
async fn deserialize_into<T: DeserializeOwned>(self) -> Result<T, serde_json::Error>;
fn deserialize_into<T: DeserializeOwned>(
self,
) -> impl Future<Output = Result<T, serde_json::Error>>;
}

View File

@ -1,7 +1,6 @@
use crate::diesel::DieselError;
use crate::diesel::get_connection::{GetConnection, GetConnectionError};
use crate::diesel::pool::PgPool;
use async_trait::async_trait;
use deadpool_diesel::Status;
use deadpool_diesel::postgres::BuildError;
use derive_more::From;
@ -32,7 +31,6 @@ pub async fn create_test_pool_url_with_size(
Ok(PoolStub(pool))
}
#[async_trait]
impl GetConnection for PoolStub {
async fn get(&self) -> Result<Object<AsyncPgConnection>, GetConnectionError> {
let mut conn = self.0.get().await?;

View File

@ -6,6 +6,7 @@ use lib::diesel::DieselError;
use testcontainers_modules::postgres::Postgres;
use testcontainers_modules::testcontainers::runners::AsyncRunner;
use testcontainers_modules::testcontainers::{ContainerAsync, TestcontainersError};
use tokio::task::JoinError;
/// When the TestContainer is dropped, the container will be removed.
/// # Errors
@ -16,11 +17,15 @@ pub struct TestContainer {
pub pool: PgPool,
}
const TEST_CONTAINERS_INTERNAL_PORT: u16 = 5432;
pub async fn create_test_containers_pool() -> Result<TestContainer, ContainerError> {
let container = create_postgres_container().await?;
let connection_string = format!(
"postgres://postgres:postgres@127.0.0.1:{}/postgres",
container.get_host_port_ipv4(5432).await?
container
.get_host_port_ipv4(TEST_CONTAINERS_INTERNAL_PORT)
.await?
);
let pool = create_pool_from_url(connection_string)?;
Ok(TestContainer::new(container, pool))
@ -36,4 +41,5 @@ pub enum ContainerError {
BuildError(BuildError),
PoolError(PoolError),
DieselError(DieselError),
JoinError(JoinError),
}