Skip to content

Support for inner types #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
carlos-verdes opened this issue Feb 21, 2025 · 1 comment
Open

Support for inner types #37

carlos-verdes opened this issue Feb 21, 2025 · 1 comment

Comments

@carlos-verdes
Copy link

This macro fails when you have inner types as context bounds of your trait functions.

Consider you have this type:

#[trait_variant::make(Aggregate: Send)]
pub trait LocalAggregate: Default + Serialize + DeserializeOwned + Sync + Send + Stream {
    type Command: Send + Sync;

    type Error: std::error::Error + From<AggregateStoreError>;
    type Services: Send + Sync;

    fn handle(
        &self,
        command: &Self::Command,
        services: &Self::Services,
    ) -> impl Future<Output = Result<Vec<Self::Event>, Self::Error>>;
}

And you want to implement a trait where you can handle this aggregate commands like this:

#[trait_variant::make(AggregateStore: Send)]
pub trait LocalAggregateStore {

    fn apply_command_and_store_events<A: Aggregate,>(
        &self,
        stream_id: &Urn,
        stream_type: String,
        metadata: crate::Metadata,
        command: A::Command,
        expected_version: Option<i64>,
    ) -> impl Future<Output = Result<(), A::Error>>
}

This fails to compile with next error:

 --> es/src/persistence/store.rs:32:9
   |
32 |         command: A::Command,
   |         ^^^^^^^ cannot infer type
   |
   = note: cannot satisfy `<_ as Aggregate>::Command == _`
@carlos-verdes
Copy link
Author

Tried changing the function to this:

fn apply_command_and_store_events<A: crate::Aggregate<Command = C>, C>(
        &self,
        stream_id: &Urn,
        stream_type: String,
        metadata: crate::Metadata,
        command: C,
        expected_version: Option<i64>,
    ) -> impl Future<Output = Result<(), A::Error>>;

Lead to next error:

note: required by a bound in `EventStore::apply_command_and_store_events`
  --> es/src/persistence/store.rs:27:42
   |
27 |     fn apply_command_and_store_events<A: crate::Aggregate<Command = C>, C>(
   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `EventStore::apply_command_and_store_events`
   = note: this error originates in the attribute macro `trait_variant::make` (in Nightly builds, run with -Z macro-backtrace for more info)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant