From 3d51b3ee572de82c0dfd2a7c1ca69c7d65ebd749 Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 27 Apr 2022 20:55:22 -0600 Subject: [PATCH] don't need static for with_transaction --- src/entity/gateway/entitygateway.rs | 8 ++++---- src/entity/gateway/inmemory.rs | 14 +++++++------- src/entity/gateway/postgres/postgres.rs | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/entity/gateway/entitygateway.rs b/src/entity/gateway/entitygateway.rs index aaf7972..d3ce500 100644 --- a/src/entity/gateway/entitygateway.rs +++ b/src/entity/gateway/entitygateway.rs @@ -19,15 +19,15 @@ pub enum GatewayError { #[async_trait::async_trait] pub trait EntityGateway: Send + Sync { - async fn transaction(&'static mut self) -> Result, GatewayError> + async fn transaction<'a>(&'a mut self) -> Result, GatewayError> { unimplemented!(); } - async fn with_transaction(&'static mut self, _func: F) -> Result + async fn with_transaction<'a, F, Fut, R, E>(&'a mut self, _func: F) -> Result where - Fut: Future, R), E>> + Send, - F: FnOnce(Box) -> Fut + Send, + Fut: Future, R), E>> + Send + 'a, + F: FnOnce(Box) -> Fut + Send, R: Send, E: From, Self: Sized diff --git a/src/entity/gateway/inmemory.rs b/src/entity/gateway/inmemory.rs index aa9762d..d9d53c7 100644 --- a/src/entity/gateway/inmemory.rs +++ b/src/entity/gateway/inmemory.rs @@ -10,13 +10,13 @@ use crate::entity::item::*; use std::sync::{Arc, Mutex}; -pub struct InMemoryGatewayTransaction { +pub struct InMemoryGatewayTransaction<'a> { working_gateway: InMemoryGateway, - original_gateway: &'static mut InMemoryGateway, + original_gateway: &'a mut InMemoryGateway, } #[async_trait::async_trait] -impl EntityGatewayTransaction for InMemoryGatewayTransaction { +impl<'a> EntityGatewayTransaction for InMemoryGatewayTransaction<'a> { fn gateway<'b>(&'b mut self) -> &'b mut dyn EntityGateway { &mut self.working_gateway } @@ -129,7 +129,7 @@ impl InMemoryGateway { #[async_trait::async_trait] impl EntityGateway for InMemoryGateway { - async fn transaction(&'static mut self) -> Result, GatewayError> + async fn transaction<'a>(&'a mut self) -> Result, GatewayError> { let working_gateway = { let users = self.users.lock().unwrap().clone(); @@ -166,10 +166,10 @@ impl EntityGateway for InMemoryGateway { } - async fn with_transaction(&'static mut self, func: F) -> Result + async fn with_transaction<'a, F, Fut, R, E>(&'a mut self, func: F) -> Result where - Fut: Future, R), E>> + Send, - F: FnOnce(Box) -> Fut + Send, + Fut: Future, R), E>> + Send + 'a, + F: FnOnce(Box) -> Fut + Send, R: Send, E: From, { diff --git a/src/entity/gateway/postgres/postgres.rs b/src/entity/gateway/postgres/postgres.rs index ceef84e..34f4ab3 100644 --- a/src/entity/gateway/postgres/postgres.rs +++ b/src/entity/gateway/postgres/postgres.rs @@ -559,17 +559,17 @@ async fn get_bank_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntit #[async_trait::async_trait] impl EntityGateway for PostgresGateway { - async fn transaction(&'static mut self) -> Result, GatewayError> + async fn transaction<'a>(&'a mut self) -> Result, GatewayError> { Ok(Box::new(PostgresTransaction { pgtransaction: self.pool.begin().await?, })) } - async fn with_transaction(&'static mut self, func: F) -> Result + async fn with_transaction<'a, F, Fut, R, E>(&'a mut self, func: F) -> Result where - Fut: Future, R), E>> + Send, - F: FnOnce(Box) -> Fut + Send, + Fut: Future, R), E>> + Send + 'a, + F: FnOnce(Box) -> Fut + Send, R: Send, E: From, {