Skip to content

Commit

Permalink
Remove useless bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
cottinisimone committed Jan 5, 2024
1 parent c61ad1b commit 2729e1f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ pub trait Aggregate {

/// Internal aggregate state. This will be wrapped in [`crate::state::AggregateState`] and could
/// be used to validate commands.
type State: Default + Send;
type State: Default;

/// A command is an action that the caller can execute over an aggregate in order to let it emit
/// an event.
type Command: Send;
type Command;

/// An event represents a fact that took place in the domain. They are the source of truth;
/// your current state is derived from the events.
type Event: Send + Sync;
type Event;

/// This associated type is used to get domain errors while handling a command.
type Error: std::error::Error + Send + Sync;
type Error: std::error::Error;

/// Handles, validate a command and emits events.
///
Expand Down
8 changes: 4 additions & 4 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ use serde::de::DeserializeOwned;
use serde::Serialize;

#[cfg(not(feature = "upcasting"))]
pub trait Event: Serialize + DeserializeOwned {}
pub trait Event: Serialize + DeserializeOwned + Send + Sync {}

#[cfg(not(feature = "upcasting"))]
impl<T> Event for T where T: Serialize + DeserializeOwned {}
impl<T> Event for T where T: Serialize + DeserializeOwned + Send + Sync {}

#[cfg(feature = "upcasting")]
pub trait Event: Serialize + DeserializeOwned + Upcaster {}
pub trait Event: Serialize + DeserializeOwned + Upcaster + Send + Sync {}

#[cfg(feature = "upcasting")]
impl<T> Event for T where T: Serialize + DeserializeOwned + Upcaster {}
impl<T> Event for T where T: Serialize + DeserializeOwned + Upcaster + Send + Sync {}

#[cfg(feature = "upcasting")]
pub trait Upcaster
Expand Down
5 changes: 0 additions & 5 deletions src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,4 @@ where
pub async fn delete(&self, aggregate_id: impl Into<Uuid> + Send) -> Result<(), E::Error> {
self.event_store.delete(aggregate_id.into()).await
}

/// Returns the internal event store
pub fn event_store(&self) -> &E {
&self.event_store
}
}
4 changes: 2 additions & 2 deletions src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl EventStoreLockGuard {
/// An EventStore is responsible for persisting events that an aggregate emits into a database, and loading the events
/// that represent an aggregate's history from the database.
#[async_trait]
pub trait EventStore: Sync {
pub trait EventStore {
type Aggregate: crate::Aggregate;
type Error: std::error::Error;

Expand Down Expand Up @@ -78,7 +78,7 @@ where
A::Event: Send + Sync,
A::State: Send,
E: std::error::Error,
T: Deref<Target = dyn EventStore<Aggregate = A, Error = E>> + Sync,
T: Deref<Target = dyn EventStore<Aggregate = A, Error = E> + Sync> + Sync,
for<'a> A::Event: 'a,
{
type Aggregate = A;
Expand Down
19 changes: 15 additions & 4 deletions src/store/postgres/event_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,28 @@ use async_trait::async_trait;
use chrono::{DateTime, Utc};
use futures::stream::BoxStream;
use futures::StreamExt;
use sqlx::{Executor, PgConnection, Pool, Postgres, Transaction};
use sqlx::pool::PoolConnection;
use sqlx::postgres::{PgAdvisoryLock, PgAdvisoryLockGuard, PgAdvisoryLockKey};
use sqlx::types::Json;
use sqlx::{Executor, PgConnection, Pool, Postgres, Transaction};
use tokio::sync::RwLock;
use uuid::Uuid;

use crate::{Aggregate, AggregateState};
use crate::bus::EventBus;
use crate::event::Event;
use crate::handler::{EventHandler, TransactionalEventHandler};
use crate::sql::event::DbEvent;
use crate::sql::statements::{Statements, StatementsHandler};
use crate::store::postgres::PgStoreError;
use crate::store::{EventStore, EventStoreLockGuard, StoreEvent, UnlockOnDrop};
use crate::store::postgres::PgStoreError;
use crate::types::SequenceNumber;
use crate::{Aggregate, AggregateState};

/// Default Postgres implementation for the [`EventStore`]. Use this struct in order to have a
/// pre-made implementation of an [`EventStore`] persisting on Postgres.
///
/// The store is protected by an [`Arc`] that allows it to be cloneable still having the same memory
/// reference.
#[derive(Clone)]
pub struct PgStore<A>
where
A: Aggregate,
Expand Down Expand Up @@ -144,6 +143,7 @@ impl UnlockOnDrop for PgStoreLockGuard {}
impl<A> EventStore for PgStore<A>
where
A: Aggregate,
A::State: Send,
A::Event: Event,
{
type Aggregate = A;
Expand Down Expand Up @@ -300,3 +300,14 @@ impl<T: Aggregate> std::fmt::Debug for PgStore<T> {
.finish()
}
}

impl<A> Clone for PgStore<A>
where
A: Aggregate,
{
fn clone(&self) -> Self {
Self {
inner: Arc::clone(&self.inner),
}
}
}

0 comments on commit 2729e1f

Please sign in to comment.