diff --git a/crates/fj-core/src/layers/layer.rs b/crates/fj-core/src/layers/layer.rs index 4f4148a9a..140f1049b 100644 --- a/crates/fj-core/src/layers/layer.rs +++ b/crates/fj-core/src/layers/layer.rs @@ -27,15 +27,21 @@ impl Layer { /// /// The command is processed synchronously. When this method returns, the /// state has been updated. - pub fn process(&mut self, command: C, events: &mut Vec) + pub fn process( + &mut self, + command: C, + events: &mut Vec, + ) -> C::Result where C: Command, { - command.decide(&self.state, events); + let result = command.decide(&self.state, events); for event in events { event.evolve(&mut self.state); } + + result } /// Drop this instance, returning the wrapped state @@ -63,6 +69,14 @@ where /// A command that encodes a request to update a layer's state pub trait Command { + /// The direct result of processing a command that is returned to the caller + /// + /// Changes to the state that result from a command are encoded as events + /// (see [`Command::Event`]). In addition to that, a command may return + /// information to the caller, and `Result` defines the type of that + /// information. + type Result; + /// An event that encodes a change to the state /// /// Events are produced by [`Command::decide`] and processed by @@ -73,7 +87,7 @@ pub trait Command { /// /// If the command must result in changes to the state, any number of events /// that describe these state changes can be produced. - fn decide(self, state: &S, events: &mut Vec); + fn decide(self, state: &S, events: &mut Vec) -> Self::Result; } /// An event that encodes a change to a layer's state diff --git a/crates/fj-core/src/layers/objects.rs b/crates/fj-core/src/layers/objects.rs index b5cff0ea2..f60ede341 100644 --- a/crates/fj-core/src/layers/objects.rs +++ b/crates/fj-core/src/layers/objects.rs @@ -36,6 +36,7 @@ pub struct InsertObject { } impl Command for InsertObject { + type Result = (); type Event = InsertObject; fn decide(self, _: &Objects, events: &mut Vec) { diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index 96071ee9e..c43fca8a5 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -21,6 +21,7 @@ impl Layer { } impl Command for InsertObject { + type Result = (); type Event = ValidationFailed; fn decide(self, state: &Validation, events: &mut Vec) {