don't need static for with_transaction
This commit is contained in:
parent
e5167ce5e0
commit
2b4c9885ee
@ -19,15 +19,15 @@ pub enum GatewayError {
|
|||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
pub trait EntityGateway: Send + Sync {
|
pub trait EntityGateway: Send + Sync {
|
||||||
async fn transaction(&'static mut self) -> Result<Box<dyn EntityGatewayTransaction + 'static>, GatewayError>
|
async fn transaction<'a>(&'a mut self) -> Result<Box<dyn EntityGatewayTransaction + 'a>, GatewayError>
|
||||||
{
|
{
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn with_transaction<F, Fut, R, E>(&'static mut self, _func: F) -> Result<R, E>
|
async fn with_transaction<'a, F, Fut, R, E>(&'a mut self, _func: F) -> Result<R, E>
|
||||||
where
|
where
|
||||||
Fut: Future<Output = Result<(Box<dyn EntityGatewayTransaction>, R), E>> + Send,
|
Fut: Future<Output = Result<(Box<dyn EntityGatewayTransaction + 'a>, R), E>> + Send + 'a,
|
||||||
F: FnOnce(Box<dyn EntityGatewayTransaction>) -> Fut + Send,
|
F: FnOnce(Box<dyn EntityGatewayTransaction + 'a>) -> Fut + Send,
|
||||||
R: Send,
|
R: Send,
|
||||||
E: From<GatewayError>,
|
E: From<GatewayError>,
|
||||||
Self: Sized
|
Self: Sized
|
||||||
|
@ -10,13 +10,13 @@ use crate::entity::item::*;
|
|||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
|
||||||
pub struct InMemoryGatewayTransaction {
|
pub struct InMemoryGatewayTransaction<'a> {
|
||||||
working_gateway: InMemoryGateway,
|
working_gateway: InMemoryGateway,
|
||||||
original_gateway: &'static mut InMemoryGateway,
|
original_gateway: &'a mut InMemoryGateway,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl EntityGatewayTransaction for InMemoryGatewayTransaction {
|
impl<'a> EntityGatewayTransaction for InMemoryGatewayTransaction<'a> {
|
||||||
fn gateway<'b>(&'b mut self) -> &'b mut dyn EntityGateway {
|
fn gateway<'b>(&'b mut self) -> &'b mut dyn EntityGateway {
|
||||||
&mut self.working_gateway
|
&mut self.working_gateway
|
||||||
}
|
}
|
||||||
@ -129,7 +129,7 @@ impl InMemoryGateway {
|
|||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl EntityGateway for InMemoryGateway {
|
impl EntityGateway for InMemoryGateway {
|
||||||
async fn transaction(&'static mut self) -> Result<Box<dyn EntityGatewayTransaction + 'static>, GatewayError>
|
async fn transaction<'a>(&'a mut self) -> Result<Box<dyn EntityGatewayTransaction + 'a>, GatewayError>
|
||||||
{
|
{
|
||||||
let working_gateway = {
|
let working_gateway = {
|
||||||
let users = self.users.lock().unwrap().clone();
|
let users = self.users.lock().unwrap().clone();
|
||||||
@ -166,10 +166,10 @@ impl EntityGateway for InMemoryGateway {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn with_transaction<F, Fut, R, E>(&'static mut self, func: F) -> Result<R, E>
|
async fn with_transaction<'a, F, Fut, R, E>(&'a mut self, func: F) -> Result<R, E>
|
||||||
where
|
where
|
||||||
Fut: Future<Output = Result<(Box<dyn EntityGatewayTransaction>, R), E>> + Send,
|
Fut: Future<Output = Result<(Box<dyn EntityGatewayTransaction + 'a>, R), E>> + Send + 'a,
|
||||||
F: FnOnce(Box<dyn EntityGatewayTransaction>) -> Fut + Send,
|
F: FnOnce(Box<dyn EntityGatewayTransaction + 'a>) -> Fut + Send,
|
||||||
R: Send,
|
R: Send,
|
||||||
E: From<GatewayError>,
|
E: From<GatewayError>,
|
||||||
{
|
{
|
||||||
|
@ -559,17 +559,17 @@ async fn get_bank_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntit
|
|||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl EntityGateway for PostgresGateway {
|
impl EntityGateway for PostgresGateway {
|
||||||
async fn transaction(&'static mut self) -> Result<Box<dyn EntityGatewayTransaction + 'static>, GatewayError>
|
async fn transaction<'a>(&'a mut self) -> Result<Box<dyn EntityGatewayTransaction + 'a>, GatewayError>
|
||||||
{
|
{
|
||||||
Ok(Box::new(PostgresTransaction {
|
Ok(Box::new(PostgresTransaction {
|
||||||
pgtransaction: self.pool.begin().await?,
|
pgtransaction: self.pool.begin().await?,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn with_transaction<F, Fut, R, E>(&'static mut self, func: F) -> Result<R, E>
|
async fn with_transaction<'a, F, Fut, R, E>(&'a mut self, func: F) -> Result<R, E>
|
||||||
where
|
where
|
||||||
Fut: Future<Output = Result<(Box<dyn EntityGatewayTransaction>, R), E>> + Send,
|
Fut: Future<Output = Result<(Box<dyn EntityGatewayTransaction + 'a>, R), E>> + Send + 'a,
|
||||||
F: FnOnce(Box<dyn EntityGatewayTransaction>) -> Fut + Send,
|
F: FnOnce(Box<dyn EntityGatewayTransaction + 'a>) -> Fut + Send,
|
||||||
R: Send,
|
R: Send,
|
||||||
E: From<GatewayError>,
|
E: From<GatewayError>,
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user