@@ -3,11 +3,12 @@ use crate::event::Event;
33use crate :: event_store:: EventStreamId ;
44use std:: fmt:: Debug ;
55
6- pub trait Command < E : Event > : Clone {
7- type State : AggregateState < E > ;
6+ pub trait Command : Clone {
7+ type Event : Event ;
8+ type State : AggregateState < Self :: Event > ;
89 type Error : std:: error:: Error + Send + Sync + ' static ;
910
10- fn handle ( & self ) -> Result < Vec < E > , Self :: Error > ;
11+ fn handle ( & self ) -> Result < Vec < Self :: Event > , Self :: Error > ;
1112
1213 fn event_stream_id ( & self ) -> EventStreamId ;
1314
@@ -26,29 +27,14 @@ pub trait Command<E: Event>: Clone {
2627 None
2728 }
2829
29- fn apply ( & mut self , event : & E )
30+ fn apply ( & mut self , event : & Self :: Event )
3031 where
3132 Self : Sized ,
3233 {
3334 self . set_state ( self . get_state ( ) . apply ( event) ) ;
3435 }
3536}
3637
37- impl < E : Event > Command < E > for ( ) {
38- type State = ( ) ;
39- type Error = std:: convert:: Infallible ;
40-
41- fn handle ( & self ) -> Result < Vec < E > , Self :: Error > {
42- Ok ( vec ! [ ] )
43- }
44- fn event_stream_id ( & self ) -> EventStreamId {
45- EventStreamId :: new ( )
46- }
47- fn get_state ( & self ) -> Self :: State { }
48- fn set_state ( & mut self , _: Self :: State ) { }
49- fn mark_retry ( & self ) -> Self { }
50- }
51-
5238pub trait AggregateState < E : Event > : Debug + Sized {
5339 fn apply ( & self , event : & E ) -> Self ;
5440}
0 commit comments